--- --- restore content begins
Spring Boot can easily create a separate Spring-based production-level applications can run. We Spring platform and third-party libraries, a self-righteous point of view, so that you can easily get started. Most Spring Boot application requires very little Spring configuration.
You can create can use java -jar or more conventional war started deploying Java applications using Spring Boot. We also offer a command-line tool to run "spring Script" is.
The main objectives are:
Provide for all Spring developers radically faster experience and entry can be widely accessible.
Out of the box, but as demand begins to deviate from the default values and quickly out of the woods.
Provide (such as embedded servers, security, metrics, health checks and externalizing configuration) common to a series of non-functional features large-scale projects.
Absolutely no code generation and does not require XML configuration.
new-project
Group: organize information, general domain inversion
Artifact: Project id
Name: Project name
Package: package name
Check the web
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</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>
Project structure
Program starts entrance SpringBootApplication
Startup project
tomcat has been launched for the 8080 port
Open Address Access
Adding controller
@RestController public class TestController { @RequestMapping(value = "/test",method = RequestMethod.GET) public String test(){ return "test"; } }
Open Address 127.0.0.1:8080/test
Project Profiles
yml properties and exist simultaneously, properties onset
application.properties
YML
How to create yml file https://www.cnblogs.com/ssjf/p/11445404.html
: Number must be spaces
server: servlet: context-path: /my port: 8081
Get the value from a configuration file
Bean can be used to create a way of getting more attributes
@Component @ConfigurationProperties(prefix = "boy") public class Boy { private String name; private Integer age; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "Boy{" + "name='" + name + '\'' + ", age=" + age + '}'; } }
@RestController public class TestController { @Autowired private Boy boy; @RequestMapping(value = "/test",method = RequestMethod.GET) public String test(){ return "姓名"+boy.getName()+"年龄"+boy.getAge(); } }
Calling multiple profiles