相关疑难解决方法(0)

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

我有一堆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

java spring dependency-injection

285
推荐指数
11
解决办法
66万
查看次数

如何在spring bean中注入String属性

我们用配置注入简单属性,如下所示:

<bean id="myService" class="com.aaa.bbb.ccc.MyServiceImpl">
    <property name="myProp" value=""/>
</bean>
Run Code Online (Sandbox Code Playgroud)

你会怎么用注释做到这一点?

java spring dependency-injection

0
推荐指数
1
解决办法
3832
查看次数

标签 统计

dependency-injection ×2

java ×2

spring ×2