Reply To: Integration with Spring Boot not working

Splash Forums PrettyFaces Users Integration with Spring Boot not working Reply To: Integration with Spring Boot not working

#27627

jpbassinello
Participant

Accordingly to http://stackoverflow.com/questions/22167912/contextloader-getcurrentwebapplicationcontext-always-returns-null

“ContextLoader isn’t really applicable to Spring Boot applications (or any with Servlet 3.0 dynamic initialization). Spring Boot does set up the ServletContext so that WebApplicationContextUtils can locate the web context. Your external artifacts really ought not to be using ContextLoader static methods since it makes assumptions about the way the app is deployed.”

I never tried “WebApplicationContextUtils” but it seems to work.

In my application, I implement a “ApplicationContextAware” that stores a static reference to the context:

public class ApplicationContextProvider implements ApplicationContextAware {
private static ApplicationContext CONTEXT;

public ApplicationContextProvider() {
}

public void setApplicationContext(ApplicationContext context) throws BeansException {
CONTEXT = context;
}

static ApplicationContext applicationContext() {
return CONTEXT;
}
}

Do you think that is way to solve it?

Thanks.