Engineering Building
The tools used in this project are:
JDK1.8
Maven
Idea
Open idea, create a new project, then right-click the project, create a new module, select Spring INITIALIZR
Then next, fill in group, artifact, and Next,
Select Web,next to complete the project creation.
The project catalog is as follows:
-src
-main
-java
-package
-springbootapplication
-resouces
-statics
-Templates
-application.yml
-test
-Pom
The pom file is as follows:
<?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 "> <modelVersion>4.0.0</modelVersion> <groupid>com.spri Ngcloud</groupid> <artifactId>springboot</artifactId> <version>0.0.1-snapshot</ version> <packaging>jar</packaging> <name>springboot</name> <description>dem o Project for Spring boot</description> <parent> <groupid>org.springframework.boot</grou Pid> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.release</v Ersion> <relativePath/> <!--lookup parent from repository to </parent> <propert Ies> <PROJECT.BUILD.SOURCEENCODING>UTF-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</ project.reporting.outputencoding> <java.version>1.8</java.version> </properties> <
;d ependencies> <dependency> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-test&
lt;/artifactid> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot&
Lt;/groupid> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </pRoject>
Modify the program entry class as follows:
/**
* @author wang_ * *
@SpringBootApplication public
class Springbootapplication extends Springbootservletinitializer {
@Override
protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {
return application.sources (Springbootapplication.class);
}
public static void Main (string[] args) {
springapplication.run (springbootapplication.class, args);
}
}
Modify the configuration file as follows:
# Server settings (serverproperties)
#端口
server.port=8082
server.address=127.0.0.1
# server.sessiontimeout=30
#访问路径名称
server.contextpath=/boot
Create a new Test.controller package and create a new Web class:
/**
* @Package: Com.springboot.test.controller
* @ClassName:
Test * @Description: Testing Web
* @Author Shuyu.wang
* @Date 2017-12-07 10:05
**/
@RestController public
class TestController {
@ Requestmapping (value = "/hello", method = requestmethod.get) public
String Hello () {
return ' Hello Spring Boot ";
}
}
Run the program and see the console:
The description program started successfully.
Then the browser accesses: Http://127.0.0.1:8082/boot/hello
Return:
Hello Spring Boot
First spring Boot project completed