spring使用注解@value取properties的值错误

applicationContext.xml 和spring-mvc.xml 各自加载了一遍,context:property-placeholder配置在spring中,mvc慢加载一步,把值给覆盖了

结论:把应该配置在applicationContext中的properties文件,配置在applicationContext.xml  里面
      把应该配置在spring-mvc中的properties文件,配置在spring-mvc.xml里面

如:
<context:property-placeholder ignore-unresolvable="true" location="classpath:*.properties"/>


或着

<context:property-placeholder ignore-unresolvable="true" location="classpath:remote.properties"/>
<context:property-placeholder ignore-unresolvable="true" location="classpath:application.properties"/>



这个问题我刚刚碰到解决了,我项目一直是好一阵坏一阵,从svn上拉下来有时候能加载上有时候加载不上

引用
<context:property-placeholder file-encoding="UTF-8" location="classpath:*.properties"/>


用这个把,关键不要写名字写*.properties,我发现spring中很多写名字的都无法加载。


参考:http://www.oschina.net/question/2309077_2139153

    http://bbs.csdn.net/topics/390601001

    http://www.xnbing.org/?p=772

猜你喜欢

转载自rd-030.iteye.com/blog/2327419