开发者

Static Fields + Autowiring in Spring

Can we autowire static fields in spring controller ?

eg:

@Autowired
    开发者_如何学JAVApublic static JNDIEMailSender jNDIEmailSender;


No, I don't think that will work. You can add a setter method, annotate it with @Autowired and set the static field in the setter.

@Autowired
void setJNDIEmailSender(JNDIEmailSender jndiEmailSender) {
  ClassName.jNDIEmailSender = jndiEmailSender
}


Spring doesnt autowire static fields

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜