spring3 mvc使用注解方式时,不能扫描jar包里面的类 
是否有人遇到过这样的问题?

解决方案 »

  1.   

    曾经遇到过,是因为web.xml里面schema的版本太小好像<web-app version小于2.5,很多服务器就认为这个软件是java 1.4的,它就不会扫描你的类要是改了还没解决的话,再贴点具体的内容上来,比如用的什么服务器,版本,没有扫描哪个jar
      

  2.   

    在你的WEB-INF/web.xml
    这一行:<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    注意那个version是不是大于2.0,而且schemaLocation指向web-app_3_0.xsd(或者2.5也行,至少要大于2.0)
      

  3.   

    上面的方式我都试过了,还是不能扫描jar里面的Controller不能被扫描
    web。xml
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">XX-servlet.xml
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><context:component-scan base-package="cn.cc.**.web" /><bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <bean id="multipartResolver"  class="org.springframework.web.multipart.commons.CommonsMultipartResolver">   
            <!-- one of the properties available; the maximum file size in bytes -->   
        </bean> 
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>xx</display-name> <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>xx.root</param-value>
    </context-param> <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param> <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/classes/applicationContext-*.xml
    </param-value>
    </context-param>
    <servlet>
    <servlet-name>xx</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>xx</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
    org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
    <session-config>
    <session-timeout>120</session-timeout>
    </session-config> <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list> <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <!-- Displays a stack trace -->
    <location>/WEB-INF/jsp/uncaughtException.jsp</location>
    </error-page></web-app>
      

  5.   

    哦,对了,你用注解的类,是否在spring配置文件中,spring只会扫描成为bean的类
      

  6.   

    你把你想spring扫描的类放到spring配置文件中,设置成session bean就好了
      

  7.   

    如果放到spring配置文件中肯定是好用的
    不过这种方式太麻烦了
      

  8.   

    那没办法,不然spring不知道你要怎么用他们,扫描了也没用啊它不知道你是要用在session,还是global,或者什么的。这些都只能在配置文件中定义
      

  9.   

    使用eclipse export工具时选中Add directory entries可以解决。