Spring object is to simplify the development of the Boot Spring application developed using the Boot Spring Spring can open a zero configuration application. Thanks to auto-configuration component in the Spring Boot, if the developers think the default configuration file does not meet the requirements,
you can configure yourself a properties
file or yml
files, fill in the configuration profile to be covered, to achieve customized results
Building project
As used herein IDEA tool to generate a Spring Boot of the project.
IDEA to create a new project, select the content of the picture in the red box
Click Next, fill the package name and the project name and other relevant information
After selecting the next step you need to add dependencies, here we do not need to add a dependent, do not check any dependencies
Then select the project file path, select the finish you can create a simple Spring Boot application
Running the Demo
main method runs the startup class, you can start the application you just created Spring Boot
After startup, the application will print out the log information in the console launch
Without exception information, then the easiest Spring Boot application has successfully built and run
Package deployment
Application Spring Boot create can run two ways, one is to package the entire project into a Jar package run directly, because the Spring Boot is integrated tomcat container.
Another way is to project a packaged into war package, and then placed in tomcat server to access applications running tomcat
For simplicity, here we first introduced the first use of the use of Jar package running, we will introduce another way how to do it later
To modify the project maven pom files are packaged as a jar
Then you can see the generated jar file
`We can use directly on the command line java -jar
to run the packaged jar file
You can see the application print out of the boot log
Simple Analysis
Miraculous discovery we have nothing to configure a Spring application can be open, this is how to do it? Start with the pom.xml
analysis of what import dependence
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>springboot-start</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
From pom file, we can see a number of import-dependent projects, namely, web, test relies, for web development support, support for testing
spring-boot-starter-parent specifies the current project is a Spring Boot project, which provides a default Maven dependent on many specific directory can be viewed 1.5.9.RELEASE repository \ org \ springframework \ boot \ spring-boot-dependencies \ the spring-boot-dependencies-1.5.9.RELEASE.pom file, where only a small portion taken:
this defines the number of versions dependent
<properties>
<spring-security.version>4.2.3.RELEASE</spring-security.version>
<spring-security-jwt.version>1.0.8.RELEASE</spring-security-jwt.version>
<spring-security-oauth.version>2.0.14.RELEASE</spring-security-oauth.version>
<spring-session.version>1.3.1.RELEASE</spring-session.version>
<spring-social.version>1.1.4.RELEASE</spring-social.version>
<spring-social-facebook.version>2.0.3.RELEASE</spring-social-facebook.version>
<spring-social-linkedin.version>1.0.2.RELEASE</spring-social-linkedin.version>
<spring-social-twitter.version>1.1.2.RELEASE</spring-social-twitter.version>
<spring-ws.version>2.4.2.RELEASE</spring-ws.version>
<sqlite-jdbc.version>3.15.1</sqlite-jdbc.version>
<statsd-client.version>3.1.0</statsd-client.version>
<sun-mail.version>${javax-mail.version}</sun-mail.version>
<thymeleaf.version>2.1.6.RELEASE</thymeleaf.version>
<thymeleaf-extras-springsecurity4.version>2.1.3.RELEASE</thymeleaf-extras-springsecurity4.version>
<thymeleaf-extras-conditionalcomments.version>2.1.2.RELEASE</thymeleaf-extras-conditionalcomments.version>
<thymeleaf-layout-dialect.version>1.4.0</thymeleaf-layout-dialect.version>
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
<thymeleaf-extras-java8time.version>2.1.0.RELEASE</thymeleaf-extras-java8time.version>
<tomcat.version>8.5.23</tomcat.version>
</properties>
...............
<dependencyManagement>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<type>test-jar</type>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<type>test-jar</type>
<version>1.5.9.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
When introducing a corresponding dependence in the project, then these will depend on the version of spring-boot-parent is defined version
Spring Boot offers many dependencies module out of the box, these modules are based on spring-boot-starter-XX named. For example, to open a web Spring Boot function, only you need to configure spring-boot-starter-web can in pom.xml
Because it relies on the spring-boot-starter-parent, so there can be no configuration version. After saving Maven will automatically help us download jar files spring-boot-starter-web module contains. If you need to view specific spring-boot-starter-web What's reliance
Of course, you can manually exclude some of us do not want to use depends on, you can use the following method
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>
We use the above way precludes tomcat dependent spring-boot-starter-web is, replaced by the use of jetty dependence
Finally, the configuration of a maven plugin
spring-boot-maven-plugin for the Spring Boot Maven plug-in, provides:
- The project packaged into an executable JAR super (uber-JAR), including all the applications that depend on the beat into the JAR file and add a description for the JAR file, the contents of which allows you to run applications with java -jar program.
- Search public static void main () method of class marked as runnable.
For a brief spring boot on this point, step by step, in-depth behind the continued introduction of content related to spring boot