I have an issue where Spring @Value
annotation not working in the constructor.
I have this Email
class that is reading some email related configuration.
In the constructor, if I put a break-point the values are empty
But if I call the sendEmail
method, there are values.
The other class:
@Autowired
Email sender;
Email
class:
@Component
public class Email{
@Value("${TO_EMAIL}")
private String toEmail;
public Email() {
// Here toEmail is null
}
public void sendEmail(String subject, String body) {
// Here toEmail has value
}
}