Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletInitializer file is created every time I create spring boot project from spring.io

Every time I create a project from spring.io a ServletInitializer file is created inside the project. I only have the spring cloud gateway dependency. Is this the reason this file exists, and if yes, could someone please explain why?

These are its contents:

package com.springcloudgatewayexample;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringCloudGatewayExampleApplication.class);
    }

}
like image 717
C96 Avatar asked Nov 16 '22 03:11

C96


1 Answers

This is the case when you choose the packaging as WAR instead of the JAR while creating a project using SpringInitializr. If you will choose the packaging as JAR (which is selected by default), then only 1 class i.e. ApplicationClass having main method and @SpringBootApplication will be created.

like image 78
Piyush Agarwal Avatar answered Apr 28 '23 20:04

Piyush Agarwal