I've read more topic about this problem but i haven't already found an answer... my problem is more general.. "ALL the bean are injected as null"
I have a class that is my ApplicationContext:
@Configuration
public class AppContext {
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource =
new ReloadableResourceBundleMessageSource();
//messageSource.setCacheSeconds(-1);
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
messageSource.setBasenames("classpath:src/main/resources/i18n/messages", "classpath:src/main/resources/i18n/errors");
return messageSource;
}
}
In my main class i load it:
private AnnotationConfigApplicationContext ctx;
public MyClassLoader() {
this.ctx = new AnnotationConfigApplicationContext(AppContext.class);
this.ctx.register(AppContext.class); // Only for test, nothing is changed
new AnotherClass();
}
And now, Anotherclass is:
class AnotherClass {
@Inject MessageSource messageSource;
public AnotherClass() {
String s = this.messageSource.getMessage("settings.title", null, Locale.ITALIAN);
System.out.println(s);
}
In AnotherClass the messageSource variable that i have injected, is null.
I've also tried to place a break-point on MessageSource @Bean to check if this is called after new AnnotationConfigApplicationContext and it is. But messageSource variable is null.