Java Spring project without Entry Point

Viewed 201

When trying to use some Spring projects from GitHub, I come across the fact that the project does not have a file with an entry point (public statics main), the question is how to launch such projects?

enter image description here

2 Answers

If the project is required to be packaged as a WAR and deployed to an application server for running , the "static main" entry point is from the application server but not your application.

In case of Tomcat , it is in the class of org.apache.catalina.startup.Bootstrap

It depends how you going to run your application. If you just want to run your project under some IDE or JAR file, declaring following main method should be enough:

@SpringBootApplication
public class BackendServerApplication {

    public static void main(String [] args) {
        SpringApplication.run(BackendServerApplication.class);
    }
}

where BackendServerApplication.class is the 'entry point' class.

If you need to deploy your application from a WAR file, you have to extend SpringBootServletInitializer class as well, but keep in mind that main method is not invoked (because, as Ken Chan mentioned, entry point is from the application server but not your application). You can learn more from here and here.

@SpringBootApplication
public class BackendServerApplication extends SpringBootServletInitializer {

    public static void main(String [] args) {
        SpringApplication.run(BackendServerApplication.class);
    }
}
Related