码迷,mamicode.com
首页 > 其他好文 > 详细

context:component-scan 分析

时间:2016-09-15 18:00:03      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

<context:component-scan>

 

Web.xml中

<servlet>

        <servlet-name>springMVC</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>classpath:springMVC.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

</servlet>

 

如下配置

<context:component-scan base-package="com.xt.web.controller" />

<context:component-scan base-package="com.xt" /> //暂时有错

springMVC.xml中需要能扫描到Controller.

否则出现:

org.springframework.web.servlet.PageNotFound noHandlerFound

警告: No mapping found for HTTP request with URI [/traffic/w] in DispatcherServlet with name ‘springMVC‘。

 

1.Web.xml中

<context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>classpath:spring-hibernate.xml</param-value>

</context-param>

 

<listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener

    </listener-class>

</listener>

 

spring-hibernate.xml文件中配置serivce,dao等spring要素。

<context:component-scan base-package="com.xt.domain" />

//路径需要到dao,service等javabean的目录的上级目录.

context:component-scan 分析

标签:

原文地址:http://www.cnblogs.com/myibm/p/5875068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!