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上拉下来有时候能加载上有时候加载不上

[quote]<context:property-placeholder file-encoding="UTF-8" location="classpath:*.properties"/>[/quote]

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


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

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

http://www.xnbing.org/?p=772
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值