1.现在web.xml中配置
web.xml中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/spring/applicationContext.xml,
classpath:config/spring/spring-a.xml
</param-value>
</context-param>
<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:config/spring/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2.在spring-a.xml和spingmvc-servlet.xml中配置扫描路径
<context:component-scan base-package="com.zhy.contoller"> <context:exclude-filter type="regex" expression=".*\.[^.]*Controller" /> </context:component-scan>
3.在spring和springmvc的配置文件中引入外置的熟悉配置文件
<context:property-placeholder location="classpath:app-config.properties, classpath:env/env-var.properties,classpath:schedule.properties" ignore-unresolvable="true"/>
注意:
springmvc的context和spring的context不是一个
由于在applicationContext.xml和springmvc-servlet.xml都配置了controller的包扫描,
相当于spring容器和springmvc都要对controller包下的bean进行初始化。第一次是spring容器初始化controller包下的bean,
由于applicationContext里引入了配置文件所以初始化时属性set进去了,而springmvc容器中没有引入配置文件,因此再次初始化时没有此属性,因此无法把配置文件中的值放进去。