【发布时间】:2020-03-15 06:54:02
【问题描述】:
由于某种原因,我正在使用外部属性源,其中一个外部属性源没有自动装配,在创建身份验证 bean 时接收到空指针
错误信息
原因:org.springframework.beans.BeanInstantiationException:无法实例化[com.filechecker.check.Authenticator]:构造函数抛出异常;嵌套异常是 java.lang.NullPointerException
原因:java.lang.NullPointerException: null 在 com.filechecker.check.Authenticator.(Authenticator.java:30) ~[classes!/:0.0.1-SNAPSHOT]
第 30 行:
String username = emailPropertyConfig.getEmailConfig().getUsername();
不工作一个
@Component
@PropertySource(value="${email.app.properties}",ignoreResourceNotFound = false)
@ConfigurationProperties
public class PropertyEmailConfiguration {
private EmailConfig emailConfig = new EmailConfig();
public EmailConfig getEmailConfig() {
return emailConfig;
}
public void setEmailConfig(EmailConfig emailConfig) {
this.emailConfig = emailConfig;
}
}
@Component
public class Authenticator extends javax.mail.Authenticator {
@Autowired
PropertyEmailConfiguration emailPropertyConfig;
@Autowired
CipherCrypt cipherCrypt;
private PasswordAuthentication authentication;
public Authenticator() throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException {
String username = emailPropertyConfig.getEmailConfig().getUsername();
String password = cipherCrypt.decrypt(emailPropertyConfig.getEmailConfig().getEncryptPassword());
authentication = new PasswordAuthentication(username, password);
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return authentication;
}
}
工作一个
@Component
@PropertySource(value="${external.app.properties}", ignoreResourceNotFound = true)
@ConfigurationProperties
public class PropertyConfiguration {
private List<FileStructureConfig> fileStructureConfig = new ArrayList();
private List<EmailSendingProperties> emailSendingProperties = new ArrayList();
public List<FileStructureConfig> getFileStructureConfig() {
return fileStructureConfig;
}
public void setFileStructureConfig(List<FileStructureConfig> fileStructureConfig) {
this.fileStructureConfig = fileStructureConfig;
}
public List<EmailSendingProperties> getEmailSendingProperties() {
return emailSendingProperties;
}
public void setEmailSendingProperties(List<EmailSendingProperties> emailSendingProperties) {
this.emailSendingProperties = emailSendingProperties;
}
}
【问题讨论】:
标签: spring-boot