But here I want to add one thing is how to access the application context?
One way is you can get the context from below method return:
ConfigurableApplicationContext applicationContext = app.run(args);
Another is if you deploy the .war to external Tomcat server, the applicationContext may be null, in this case, you can get it from onStartup() method
@Overridepublic void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext rootAppContext = createRootApplicationContext(servletContext); if (rootAppContext != null) {
// set context into your own class, say MySpringContext here MySpringContext.setContext(rootAppContext); servletContext.addListener(new ContextLoaderListener(rootAppContext) { @Override public void contextInitialized(ServletContextEvent event) { // no-op because the application context is already initialized } }); } else { this.logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not " + "return an application context"); } }