Is it possible to deploy a external war file in embedded/inbuilt tomcat server in spring boot?

243 views Asked by At

I want to deploy opencms.war/any war file (Which is not built on spring boot but it can be run on any application or web servers) in spring boot application inbuilt embedded server. Can any one please help me on this?

1

There are 1 answers

1
Sumedh Jogdande On BEST ANSWER

Just try with this approach. add this code block in your spring boot application. place your war file in a src/main/resources directory.

@Bean
    public EmbeddedServletContainerFactory servletContainerFactory() {
        return new TomcatEmbeddedServletContainerFactory() {

            @Override
            protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {

                new File(tomcat.getServer().getCatalinaBase(), "webapps").mkdirs();

                try {

                    tomcat.addWebapp("/test", new ClassPathResource("test.war").getFile().toString());

                } catch (Exception ex) {
                    throw new IllegalStateException("Failed to add webapp",ex);
                }
                return super.getTomcatEmbeddedServletContainer(tomcat);
            }
        };

    }