我正在使用带有 spring-mvc 和 spring-security 的 @Autowired 注释,它可以工作,但是 webapp 启动非常慢,每次大约 1 分钟,因为 spring-mvc 和 spring-security 扫描了所有自动装配的类和总数大约 500 个班级。有什么建议可以加快扫描时间吗?还是静态xml配置更好?
在 web.xml 中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/rest-servlet.xml
</param-value>
</context-param>
<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>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
....
在 rest-sevlet.xml
<context:component-scan base-package="com.mycomp" />
<mvc:annotation-driven />
<mvc:interceptors>
....
</mvc:interceptors>
<import resource="classes/config/applicationContext-security-base.xml"/>
<import resource="classes/config/applicationContext-security.xml"/>
<import resource="classes/config/spring-aop.xml"/>
<!-- i18n -->
<import resource="classes/config/spring-locale.xml"/>