为了账号安全,请及时绑定邮箱和手机立即绑定

如何将属性值注入使用注释配置的Spring Bean?

如何将属性值注入使用注释配置的Spring Bean?

一只斗牛犬 2019-07-27 15:24:40
如何将属性值注入使用注释配置的Spring Bean?我有一堆Spring bean,它们是通过注释从类路径中获取的,例如@Repository("personDao")public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {     // Implementation omitted}在Spring XML文件中,定义了一个PropertyPlaceholderConfigurer:<bean id="propertyConfigurer"    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">     <property name="location" value="/WEB-INF/app.properties" /></bean>我想将app.properites中的一个属性注入上面显示的bean中。我不能简单地做一些事情<bean class="com.example.PersonDaoImpl">     <property name="maxResults" value="${results.max}"/></bean>因为PersonDaoImpl在Spring XML文件中没有特征(它是通过注释从类路径中获取的)。我有以下几点:@Repository("personDao")public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {     @Resource(name = "propertyConfigurer")     protected void setProperties(PropertyPlaceholderConfigurer ppc) {     // Now how do I access results.max?      }}但是我不清楚我如何访问我感兴趣的房产ppc?
查看完整描述

3 回答

?
catspeake

TA贡献1111条经验 获得超0个赞

有一个新的注释@Value春季3.0.0M3@Value不仅支持#{...}表达式,还支持${...}占位符


查看完整回答
反对 回复 2019-07-27
  • 3 回答
  • 0 关注
  • 836 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信