我有一堆Spring bean,它们是通过注释从类路径中获取的,例如
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
// Implementation omitted
}
Run Code Online (Sandbox Code Playgroud)
在Spring XML文件中,定义了一个PropertyPlaceholderConfigurer:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我想将app.properites中的一个属性注入上面显示的bean中.我不能简单地做一些事情
<bean class="com.example.PersonDaoImpl">
<property name="maxResults" value="${results.max}"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
因为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?
}
}
Run Code Online (Sandbox Code Playgroud)
但是我不清楚我如何访问我感兴趣的房产ppc?
我们用配置注入简单属性,如下所示:
<bean id="myService" class="com.aaa.bbb.ccc.MyServiceImpl">
<property name="myProp" value=""/>
</bean>
Run Code Online (Sandbox Code Playgroud)
你会怎么用注释做到这一点?