Monday 25 May 2020

Spring boot Create a Deployable War File

It is easy to follow https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

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");
    }
}

2 comments:

  1. I am very happy to share this amazing testimony Dr.Oje Abacha herbs help me to cure my Herpes Simplex Disease and i was haven this Herpes 3 months ago.. i had unprotected sex with a man i met and he did tell me he had Herpes disease after some weeks later i started seeing bump and sore on my vaginal, and i was so scared so i went to my doctor and did some test and behold i was confirmed Herpes positive, i went home so confused and frustrated about this, especially when i was told there was no permanent cure for it, i said to myself i need to research about this, maybe there might be a herbal help for me, and so i did and when i was researching about herbal herbs, i keep seeing Dr.Oje Abacha on every blog and guestbook, so i immediately wrote to Dr.Oje Abacha, after we discuss he prepared my medicine and sent it to me, within few days i received my medicine and started applying it as instructed within 2weeks Dr.Oje Abacha told me to go for check up, and i did, shocking my result came out negative, i am so happy thanks to you sir,
    contact his email address,
     oje.herbalsolutioncentre@gmail.com  
    more information WhatsApp Number : +2349050957732
    by Dr.Oje Abacha website

    https://ojeherbalsolutioncentre.wordpress.com

    ReplyDelete