是否可以通过@Autowired将PropertyPlaceholder中的属性添加到bean中?我无法在xml-context-config中注入它,因为bean以这种方式加载:
<context:component-scan base-package="..."/>
Run Code Online (Sandbox Code Playgroud)
在3.0版本(我认为来自里程碑3),您可以使用@Value("$ {foo.bar}")来访问PropertyPlaceholder中的属性.
春季2.5方法:
@Component
public class Foo {
@Autowired
@Qualifier("myFlag")
private Boolean flag;
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
和背景
<context:component-scan base-package="..."/>
<context:property-placeholder location="classpath:app.properties"/>
<!-- the flag bean -->
<bean id="myFlag" class="java.lang.Boolean">
<constructor-arg value="${foo.bar}"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
干杯
| 归档时间: |
|
| 查看次数: |
3945 次 |
| 最近记录: |