Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
- 简化Spring应用开发的一个框架
- 整个Spring技术栈的一个大整合
- J2EE开发的一站式解决方案
微服务:每一个功能元素最终都是一个可独立替换和独立升级的软件单元。
详情参考:微服务文档
在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>
功能:浏览器发送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>
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);
}
}
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!";
}
}
运行结果:
打开浏览器访问: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>
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入门教程(超详细)的全部内容。
看完如果对你有帮助,感谢点赞支持!
如果你是电脑端的话,看到右下角的 “一键三连” 了吗,没错点它[哈哈]
加油!
共同努力!
Keafmd