首页 > spring4.2没办法创建其他jar包的spring配置文件中定义的bean么?

spring4.2没办法创建其他jar包的spring配置文件中定义的bean么?

最近想写点个人项目,用的springmvc,版本是4.2。
项目里有一个common.jar,各个模块需要用的工具类这些的放这里面。其中定义了共用的配置文件读取,配置如下:

spring-common.xml

<context:property-placeholder file-encoding="UTF-8" ignore-resource-not-found="true" properties-ref="commonConfigProperties" ignore-unresolvable="true"/>
<bean id="commonConfigProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>classpath:common-conf.properties</value>
        </list>
    </property>
    <property name="fileEncoding" value="UTF-8"/>
</bean>

在一个web项目中依赖了这个jar包,web项目配置如下:

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring.xml</param-value>
</context-param>

spring.xml

<import resource="classpath*:spring-common.xml" />

然后在一个@Controller里用@Value来自动注入配置文件中定义的属性

@Value("#{commonConfigProperties['default.redirecturi']}")

结果启动报错,说是找不到配置的Properties。折腾了半天我把spring.xml里的import去掉,把spring-common.xml里的配置直接拷贝到spring.xml中,好使了。。。
但是在其他模块里也会用到common的配置,我难道需要没个模块都拷贝一下么,import为什么不好使呢?


<import resource="classpath:spring-common.xml" /> 这个路径不对,没有指引到正确的路径,应该是<import resource="classpath:WEB-INF/你自己的路径/spring-common.xml" />

【热门文章】
【热门文章】