Spring Boot教程一:工程构建
来源:互联网 发布:无添加面膜知乎 编辑:程序博客网 时间:2024/06/07 02:08
工程搭建
本文工程搭建使用的工具:
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_ */@SpringBootApplicationpublic 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=8082server.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 **/@RestControllerpublic 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工程完成
阅读全文
0 0
- Spring Boot教程一:工程构建
- Spring Boot教程一
- spring boot 教程(一) 构建我的第一个Spring boot
- 通过Spring Boot构建项目工程
- spring boot 第一篇 构建第一个spring boot工程
- Spring Boot 教程(二)Spring Boot 构建框架
- Spring Boot构建interceptor简明教程
- Spring Boot (教程一: 入门)
- 【Spring Boot教程】快速搭建spring boot项目工程
- spring boot 学习一之基础构建
- Spring Boot (一) maven构建springboot初探
- spring-boot笔记-工程搭建(一)
- Spring Boot 教程(一)---入门篇
- Spring Boot 教程(一)---入门篇
- Spring Boot实践教程(一):Hello,world!
- Maven快速使用教程(二) spring boot 项目构建
- Spring Boot构建应用
- maven构建Spring Boot
- yarn init 报错
- js中三种作用域详解(全局,函数,块级)
- 第14周项目1(2)- 验证算法 希尔排序
- upupw环境下加载 Yii2的入口文件不能正常加载
- 第十三周项目五
- Spring Boot教程一:工程构建
- 第8周 项目3- 对称矩阵压缩存储的实现与应用(3)
- dom4j api 详解
- python
- 坑爹的生活,源于你的工作谁都能干
- python中的input
- ida 6.95动态调试ios
- 12月书单
- greenplum