2

I have email config class like this.

@Configuration
public class EmailConfiguration {

    @Autowired
    private ConfigService configService;


    @Bean
    public JavaMailSender JavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(configService.emailHost());
        mailSender.setPort(configService.emailPort());
        mailSender.setUsername(configService.emailAddress());
        mailSender.setPassword(configService.emailPassword());

        return mailSender;
    }
}

how to make this bean change the value at runtime every ConfigService was refreshed? I was refresh the ConfigService but the bean's value did not change.

kams
  • 21
  • 1
  • 4

1 Answers1

0

There is a way to handle property refresh in Spring boot. Please check this once - https://www.baeldung.com/spring-reloading-properties.

This will make use of spring in-built capabilities to handle property changes. And will be extensible for future purposes as well.