Preface:
What Spring boot is and what issues are resolved
1) Spring boot makes coding easy
2) Spring boot makes configuration easy
3) Spring boot makes deployment simple
4) Spring boot makes monitoring easy
Since spring boot is positioned to address microservices, its service containers are integrated internally, so there is no need for additional deployment, just start springapplication.
Sometimes, however, you need to separate the project code from the service, package the code into a war, and then deploy it to Tomcat or jetty,weblogic. Spring boot, in addition to the built-in service container, is also compatible with the separation of services, specifically configured as follows:
1, configuration pom.xml dependency,
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>com.sam.project.service</groupId> <artifactid>spring_ Boot_service</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version > <name>spring_boot_service Maven webapp</name> <url>http://maven.apache.org</url> < Parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-parent </artifactId> <version>1.5.1.RELEASE</version> </parent> <dependencies> <dependen Cy> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-web</ artifactid> </dependency> <dependency> <groupid>oRg.springframework.boot</groupid> <artifactId>spring-boot-starter-tomcat</artifactId> < scope>provided</scope> </dependency> </dependencies> <build> <finalname>spring_bo Ot_service</finalname> </build> </project>
2. Configure the boot entry:
Package com.sam.project.service;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import Org.springframework.boot.builder.SpringApplicationBuilder;
Import Org.springframework.boot.web.support.SpringBootServletInitializer;
Import org.springframework.cache.annotation.EnableCaching;
/**
* @ClassName: Application
* @Description: Springboot launcher *
/
@EnableCaching
@ Springbootapplication public
class application extends Springbootservletinitializer {
@Override
Protected Springapplicationbuilder Configure (Springapplicationbuilder application) {
return Application.sources (Application.class);
}
public static void Main (string[] args) {
springapplication.run (application.class, args);
}
}
2, Project name configuration:
in the Application.properties file, add:
Server.contextpath=/spring_boot_service
Summary: Separating built-in services requires only one place to configure, the Tomcat reference:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-tomcat</artifactid>
<scope>provided</scope>
</dependency>
After the configuration is complete, you can add it to the container for deployment, or package the war for deployment, as shown in the following illustration:
Successfully started.