Using Spring IoC allows to set bean properties exposed via setters:
public class Bean {
private String value;
public void setValue(String value) {
this.value = value;
}
}
And the bean definition is:
<bean class="Bean">
<property name="value" value="Hello!">
</bean>
Is there any existing plugins/classes for Spring Framework that allows to directly expose bean fields as properties without defining setters? Something like this with the same bean definition:
public class Bean {
@Property
private String value;
}
You can:
@Value
annotation and inject a property (using expression language)Spring supports annotation-based field injection out of the box for the JSR-250 @Resource
annotation. Spring's own @Autowired
and JSR 330's @Inject
also work.
You just need to add this line to your context.xml:
<context:annotation-config/>
Reference:
@Autowired
and @Inject
@Resource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With