Spring RESTful Service as a WAR instead of JAR in Tomcat

前端 未结 3 2168
感动是毒
感动是毒 2020-12-15 19:21

I am in the process of creating a REST web service in Java Spring. I\'ve successfully loaded STS and the example detailed at :

\"This guide walks you through the pr

3条回答
  •  悲哀的现实
    2020-12-15 19:38

    (Answer from OP moved from question to here)

    Boy I feel really dumb.. Found there was more to the tutorial after changing the gradle instructions.. including the very needed Auto Configuration that supercedes/replaces the need for a web.xml

    Solution

    Initialize the servlet

    Previously, the application contained a public static void main() method which the spring-boot-gradle-plugin was configured to run when using the java -jar command.

    By converting this into a WAR file with no XML files, you need a different signal to the servlet container on how to launch the application.

    src/main/java/hello/HelloWebXml.java

    package hello;
    
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.SpringBootServletInitializer;
    
    public class HelloWebXml extends SpringBootServletInitializer {
    
      @Override
      protected void configure(SpringApplicationBuilder application) {
         application.sources(Application.class);
      }
    
    }
    

    Will give credit to the first answer, but you both were correct that the web.xml (or what Spring-Boot uses to replace it) was needed.

提交回复
热议问题