My program works fine when running it from IntelliJ IDE, but when I'm using it from a docker file it gives this error:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-26 13:48:35.598 ERROR 19 --- [ main] o.s.boot.SpringApplication : Application run failed
Which will consequently throw a nullPointerException and can't get the beans.
I have defined the following class
@Component
public class ApplicationContextUtils implements ApplicationContextAware {
private static ApplicationContext ctx;
@Override
public void setApplicationContext(ApplicationContext appContext)throws BeansException {
ctx = appContext;
}
public static ApplicationContext getApplicationContext() {
return ctx;
}
}
And on my RabbitMQ I do:
ApplicationContext appCtx = ApplicationContextUtils.getApplicationContext();
FirebaseMessage firebaseMessage = appCtx.getBean(FirebaseMessage.class);
RabbitMQRequester rabbitMQRequester = appCtx.getBean(RabbitMQRequester.class);
I don't get why it works on the IDE and not on the docker-compose with a docker file build