Get the App
SLTechnology News&Howtos  ›  Development  › 

How does springboot turn off the tomcat container?

Shulou Source: shulou.com Published: 2022-06-02 16:44:43 10月21日 Update

This article mainly introduces "how to close the tomcat container by springboot". In the daily operation, I believe many people have doubts about how to close the tomcat container by springboot. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to turn off the tomcat container by springboot". Next, please follow the editor to study!

Springboot, turn off the tomcat container.

Sometimes what you need to provide is not HTTP services, but RPC services, but you want to use the convenient support provided by springboot.

At this point, you need to shut down the RPC service and then add your own daemon thread in the main function.

Public static void main (String [] args) {SpringApplication app = new SpringApplication (Application.class); app.setWebApplicationType (WebApplicationType.NONE); app.run (args);} springboot uses third-party tomcat1. Change to pom

Because the code uses servlet's api, if you don't add it, you will report an error. Remove tomcat from web module

Org.springframework.boot spring-boot-starter-web spring-boot-starter-tomcat org.springframework.boot Javax.servlet javax.servlet-api provided

Plug-in comments the original springboot-maven plug-in, changed to war

You can change your name in warName, and this is the name of the package you will type.

Org.apache.maven.plugins maven-war-plugin springboot

Change the way of packing

War2. Add a startup class

Inherit SpringBootServletInitializer override configure method

@ SpringBootApplication@Configuration @ ComponentScan (basePackages= "com.jubao.dling") / / the default scan is the path under the current package @ EnableAutoConfiguration public class DlingApplication extends SpringBootServletInitializer {public static void main (String [] args) {SpringApplication.run (DlingApplication.class, args);} @ Override protected SpringApplicationBuilder configure (SpringApplicationBuilder application) {return application.sources (DlingApplication.class);}}

It is not necessary to delete the original startup class, because usually when developing, you must still use the built-in tomcat, and the tags that remove tomcat will be commented out during development.

3. Pack the war bag

Release tomcat to run

At this point, the study on "how to close the tomcat container by springboot" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Containers learning services plug-ins methods time more comments help development practical ordinary time next code functions then that is articles ways Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno MariaDB Shulou Information NVidia