Lison <cundream@163.com>
, v1.0.0, 2019.10.13
SpringBoot系统搭建集成-001-工程构建建
工程搭建
使用搭建工具:
- JDK1.8
- Maven
- IDEA
打开idea,新建一个project,然后右键工程,新建一个module,选择Spring Initializr
然后next,填写group、artifact ,然后next,
选择web,next完成工程创建
工程目录如下:
- src
-main
-java
-package
-SpringbootApplication
-resouces
- statics
- templates
- application.properties
-test
- pom
pom文件如下 :
<?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.springcloud</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springboot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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>
修改程序入口类如下:
/**
* @author Lison
*/
@SpringBootApplication
public class SpringbootbuildingApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootbuildingApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringbootbuildingApplication.class, args);
}
}
修改配置文件如下:
# Server settings (ServerProperties)
#端口
server.port=8082
server.address=127.0.0.1
#server.sessionTimeout=30
#访问路径名称
server.contextPath=/bootbuliding
新建一个test.controller包,新建一个web类:
/**
* @author : Lison
* @Date: 2019/10/15 10:25
* @Description: 测试web
*/
@RestController
public class TestController {
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String hello(){
return "hello Spring boot";
}
}
运行程序看控制台
说明程序启动成功了。
然后浏览器访问:http://127.0.0.1:8082/bootbuliding/hello
响应结果