Does @Value field injection require to be under a @RestController / @Configuration class for it to work?
I went through countless tutorials no one seem to mention anything like it, but wen I tried on my own code it just doesn't work. I found suppose solution here: Spring Boot application.properties value not populating But it didn't work in my case.
public class AuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@Value("${token.secret}")
private String tokenSecret; <--- always null
@Value("${token.expiration_time}")
private String tokenTime; <--- always null
...
@PostConstruct <-- this was suggested but still null
public void init(){
log.info("tokenTime : {}", tokenTime);
log.info("tokenSecret: {}", tokenSecret);
}
}
I then moved these fields to my @Configuration or @RestController class the values does get populated, why is that? and how to fix this in my AuthenticationFilter
?
@Configuration
@EnableWebSecurity
public class AppWebSecurity extends WebSecurityConfigurerAdapter {
@Value("${token.secret}")
private String tokenSecret;
@Value("${token.expiration_time}")
private String tokenTime;
....
}
Thank you