SpringBoot2.1.5(3)----开发第一个应用
1.开发前检查一下环境
2.IDEA 创建maven 项目
然后我们打开 官方文档 ,用目前最新正式发布版是 Spring Boot 2.1.5.RELEASE, 我们复制相关依赖到我们的maven 项目中
生成Sample.zip,解压后导入。
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 http://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.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zyzx</groupId>
<artifactId>Sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Sample</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>
增加一个SimpleController类
package com.zyzx.Sample;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class SimpleController {
@RequestMapping("/")
String home() {
return "Hello World!";
}
在application.properties中修改端口
server.port=8090
运行程序:
测试:在浏览器中输入
OK ,至此,我们的手工创建web应用 就完成!