Reputation: 142
Can we autowire static fields in spring controller ?
eg:
@Autowired
public static JNDIEMailSender jNDIEmailSender;
Upvotes: 4
Views: 11292
Reputation: 21000
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
}
Upvotes: 10