1.

How can you change output artefact of Spring Boot application from jar to WAR?

Answer»
  • For this, you will extend SpringBootServletInitializer 
@SpringBootApplication public class MyWebApplication extends SpringBootServletInitializer{     @OVERRIDE     protected SpringApplicationBuilder CONFIGURE(SpringApplicationBuilder application) {         return application.sources(MyWebApplication.class);     }     public static void main(String[] ARGS) {         SpringApplication.run(MyWebApplication.class, args);     } }
  • Packaging Type in pom.xml needs to be DEFINED as :
<packaging>war</packaging>
  • Add spring-boot-starter-tomcat as the provided SCOPE
<dependency>       <groupId>org.springframework.boot</groupId>       <artifactId>spring-boot-starter-tomcat</artifactId>       <scope>provided</scope>   </dependency>


Discussion

No Comment Found