How to deploy spring boot web application on tomcat server

后端 未结 5 940
清歌不尽
清歌不尽 2020-12-04 16:50

I have created spring boot web application, but I am unable to deploy spring boot web application WAR file on tomcat and I am able to run it as java application. How to run

5条回答
  •  时光说笑
    2020-12-04 17:29

    Here are two good documentations on how to deploy the Spring Boot App as a war file.

    You can follow this spring boot howto-traditional-deployment documentation -

    Steps according to this documentation -

    1. You update your application’s main class to extend SpringBootServletInitializer.

    2. The next step is to update your build configuration so that your project produces a war file rather than a jar file. war

    3. Mark the embedded servlet container dependency as provided.

      
          org.springframework.boot
          spring-boot-starter-tomcat
          provided
      
      

    and one more way -

    See this spring io documentation which outlines how to deploy the spring boot app to an application server.

    Steps -

    1. Change jar packaging to war.

    2. Comment out the declaration of the spring-boot-maven-plugin plugin in your pom.xml

    3. Add a web entry point into your application by extending SpringBootServletInitializer and override the configure method

    4. Remove the spring-boot-starter-tomcat dependency and modfiy your spring-boot-starter-web dependency to

    
      org.springframework.boot
      spring-boot-starter-web
        
            
                org.springframework.boot
                spring-boot-starter-tomcat
            
        
    
    

    In your pom.xml, remove spring-beans and spring-webmvc dependencies. The spring-boot-starter-web dependency will include those dependecies.

提交回复
热议问题