工程搭建
本文工程搭建使用的工具:
JDK1.8
Maven
idea
打开idea,新建一个project,然后右键工程,新建一个module,选择Spring Initializr
然后next,填写group、artifact ,然后next,
选择web,next完成工程创建。
工程目录如下:
- src
-main
-java
-package
-SpringbootApplication
-resouces
- statics
- templates
- application.yml
-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 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);
}
}
修改配置文件如下:
# Server settings (ServerProperties)
#端口
server.port=8082
server.address=127.0.0.1
#server.sessionTimeout=30
#访问路径名称
server.contextPath=/boot
新建一个test.controller包,新建一个web类:
/**
* @Package:com.springboot.test.controller
* @ClassName:test
* @Description:测试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";
}
}
运行程序,看到控制台:
说明程序启动成功了。
然后浏览器访问:http://127.0.0.1:8082/boot/hello
返回:
hello Spring boot
第一个spring boot工程完成
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/15863.html