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
精彩评论