- Spring Boot 简介
- 微服务
- 环境准备
- maven设置
- IDEA设置
- 使用SpringBoot创建一个HellWorld应用
- 1、创建一个maven工程(spring-boot-01-helloworld)
- 2、在pom.xml中导入spring boot相关的依赖
- 3、编写一个主程序
- 4、编写相关的Controller
- 5、运行主程序
- 简化部署
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
微服务
- 简化Spring应用开发的一个框架
- 整个Spring技术栈的一个大整合
- J2EE开发的一站式解决方案
微服务:每一个功能元素最终都是一个可独立替换和独立升级的软件单元。
详情参考:微服务文档
环境准备- jdk1.8:Spring Boot 推荐jdk1.7及以上
- maven3.x:maven 3.3以上版本
- IntelliJIDEA:或者STS
- SpringBoot 1.5.9.RELEASE:1.5.10
在maven 的settings.xml配置文件的profiles标签添加以下配置:
<profile> <id>jdk‐1.8id> <activation> <activeByDefault>trueactiveByDefault> <jdk>1.8jdk> activation> <properties> <maven.compiler.source>1.8maven.compiler.source> <maven.compiler.target>1.8maven.compiler.target> <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion> properties> profile>
讯享网
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
把maven整合到idea。
讯享网
功能:浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串。
项目目录:
讯享网<parent> <artifactId>spring-boot-dependenciesartifactId> <groupId>org.springframework.bootgroupId> <version>1.5.10.RELEASEversion> parent>
<dependencies> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-webartifactId> dependency> dependencies>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
HelloWorldMainApplication:
package com.keafmd;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/ Keafmd * @ClassName: HelloWorldMainApplication * @Description: 主程序 * @author: 牛哄哄的柯南 @date: 2021-02-22 15:00 / @SpringBootApplication public class HelloWorldMainApplication { public static void main(String[] args) {
//Spring应用启动起来 SpringApplication.run(HelloWorldMainApplication.class,args); } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7

- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
HelloController:
讯享网package com.keafmd.controller;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
/ Keafmd * @ClassName: HelloController * @Description: * @author: 牛哄哄的柯南 @date: 2021-02-22 15:04 / @Controller public class HelloController {
@ResponseBody @RequestMapping(“/hello”) public String hello(){ return ”Hello World!“; } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23

运行结果:
打开浏览器访问:http://localhost:8080/hello
简化部署OK,至此,第一个SpringBoot的HelloWorld就大功告成了。【amazing~】
1、我们在pom.xml文件中假如以下代码:
<build> <plugins> <plugin> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-maven-pluginartifactId> <executions> <execution> <goals> <goal>repackagegoal> goals> execution> executions> plugin> plugins> build>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
2、然后,我们将应用打包
3、然后再target文件夹下就可以看到spring-boot-01-helloworld-1.0-SNAPSHOT.jar
4、复制到桌面(随便哪,个人选择),打开cmd窗口,切换到jar包所在位置,我的是桌面,然后输入:java -jar spring-boot-01-helloworld-1.0-SNAPSHOT.jar,运行效果如下。
5、打开浏览器访问:http://localhost:8080/hello,同样可以看到HelloWord
这样的部署就变得十分简单了。
以上就是SpringBoot入门教程(超详细)的全部内容。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/146478.html