在static静态变了中使用注入方式
0.@Component注解
需要在类上添加 @Component
1.注入类
private static JavaMailSender javaMailSender;
@Autowired
public AsyncFactory(JavaMailSender javaMailSender) {
AsyncFactory.javaMailSender = javaMailSender;
}
2.读取配置文件
private static String emailAccount;
@Value("${spring.mail.username}")
public void setEmailAccount(String emailAccount) {
AsyncFactory.emailAccount = emailAccount;
}
public String getEmailAccount() {
return emailAccount;
}