春豆田注射 [英] Spring bean fields injection

查看:102
本文介绍了春豆田注射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Spring IoC允许设置通过setter公开的bean属性:

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;
    }
}

并且bean的定义是:

And the bean definition is:

<bean class="Bean">
    <property name="value" value="Hello!">
</bean>

是否有任何现有的Spring Framework插件/类允许直接将bean字段作为属性公开而不定义setter方法?具有相同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;
}


推荐答案

你可以:


  • 使用 @Value 注释并注入属性(使用表达式语言)

  • 查看 Project Lombok ,它将让您跳过所有的安装者和吸气者(等等) )

  • use the @Value annotation and inject a property (using expression language)
  • take a look at Project Lombok, which will let you skip all setters and getters (and more)

这篇关于春豆田注射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆