Vla*_*mir 10 java spring dependency-properties inversion-of-control javabeans
使用Spring IoC允许设置通过setter公开的bean属性:
public class Bean {
private String value;
public void setValue(String value) {
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
而bean的定义是:
<bean class="Bean">
<property name="value" value="Hello!">
</bean>
Run Code Online (Sandbox Code Playgroud)
是否有任何现有的Spring Framework插件/类允许直接将bean字段作为属性公开而不定义setter?像这样的bean具有相同的bean定义:
public class Bean {
@Property
private String value;
}
Run Code Online (Sandbox Code Playgroud)
您可以:
@Value注释并注入属性(使用表达式语言)Spring 为JSR-250注释提供了开箱即用的基于注释的字段注入.Spring自己和JSR 330的也行. @Resource@Autowired@Inject
您只需要将此行添加到context.xml:
<context:annotation-config/>
Run Code Online (Sandbox Code Playgroud)
参考:
| 归档时间: |
|
| 查看次数: |
11419 次 |
| 最近记录: |