**Custom configuration for mail sender **
JavaScript
x
@Configuration
public class EmailConfig {
private EmailProperties emailProp;
@Autowired
ConstantRepository constantRepository;
public EmailConfig(EmailProperties emailProp) {
this.emailProp = emailProp;
}
@Bean
public JavaMailSender getJavaMailSender() {
Constants cons = constantRepository.findByConstantKeyAndStatus("DEFAULT_MAIL_ACCOUNT_CREDENTIAL",true);
String password = cons.getValue();
}
here I am trying to fetch the password from the database but the problem is while building the app it calls the repository which leads to failure as IP whitelisting issue it is getting error: unable to acquire JDBC connection.
How to stop these repo calls while building the app
Advertisement
Answer
You can use @Lazy annotation at the Configuration level. So that the beans will be created at runtime when requested for First-time.
JavaScript
@Configuration
@Lazy
public class EmailConfig {
private EmailProperties emailProp;
@Autowired
ConstantRepository constantRepository;
public EmailConfig(EmailProperties emailProp) {
this.emailProp = emailProp;
}
@Bean
public JavaMailSender getJavaMailSender() {
Constants cons = constantRepository.findByConstantKeyAndStatus("DEFAULT_MAIL_ACCOUNT_CREDENTIAL",true);
String password = cons.getValue();
}