Spring Boot starter Six service configuration and integration

Source: Internet
Author: User
Tags xmlns tomcat


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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.