- Spring Boot war包启动
- 什么是Spring boot
- 快速了解Spring Boot
- Spring boot入门实例
- springboot 整合freemarker
- Spring Boot使用FastJson解析JSON数据
- Spring Boot上传文件示例
知识点
相关文章
更多最近更新
更多Spring boot入门实例
2019-03-01 22:54|来源: 网路
入门实例是基于maven工程,主要配置:
spring boot 父节点依赖,引入这个之后相关的引入就不需要添加version配置,spring boot会自动选择最合适的版本进行添加。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
添加spring-boot-starter-web依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
完整pom.xml配置文件
<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>h.y.n</groupId>
<artifactId>demo-spring-boot-hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
创建一个Controller
package h.y.n.springboot.hello.controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String say(@PathVariable("name") String name) {
return "Hi " + name;
}
}
新建启动类(App – Main方法)
package h.y.n.springboot.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
直接运行main方法即可,访问http://localhost:8080/hello/656463,响应 hi 656463
相关问答
更多-
spring boot 应该如何入门?[2022-04-05]
原因如一下: 1) Spring Boot使编码变简单。 2) Spring Boot使配置变简单。 3) Spring Boot使部署变简单。 4) Spring Boot使监控变简单。 -
一个最简单的 spring boot restful 例子。[2023-08-01]
建议你这样试试看: 1. 在 Eclipse 中新一个 maven 工程。 2. 修改 pom.xml 文件添加如下内容: 3. org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.bo ... -
是不是有一款什么手机软件,可以很自然的拉长腿部?不是美图秀秀,有知道的不?[2022-10-20]
spring -
spring boot 和spring framework到底学哪个啊?[2023-06-13]
先学spring framework吧,把spring 的原理,配置那些东西学会了,理解了再去用spring boot 很容易上手,其实spring boot 就是把很多spring 的配置都简化了,很多东西在properties配置文件里写了之后,spring boot 就会自动帮你把相关的bean配置上,例如你在配置文件里把数据库连接的相关地址,用户,密码配好后,spring boot就会自动帮你把数据库连接池配置好,当然你也可以不用他提供的自动配置功能,完全可以按照你的需求去集成其他的例如dbcp,c ... -
春天的英语怎么读?[2022-05-21]
spring -
你为什么不自己初始化它。 @Bean ObjectMapper objectMapper() { return new ObjectMapper(); } You can add spring-boot-starter-json if you want to avoid to include the full web stack (since Spring Boot v.2.0.0M4).
-
我个人的建议是肯定使用Spring Boot的原因很多。 首先是Boot是“Spring的未来”。 有了这个话,我想说的是,通过Boot,您可以受益于Spring社区的许多承诺,今天的大多数Spring项目都与Boot完全集成,即使是社区也开始开发基于Boot的许多应用程序。 例如对于管理和监视我可以建议看到Spring Boot Admin 使用弹簧启动,您可以受益于非常好的和有用的功能,如执行器和远程管理和监控,可以改善您的应用程序与生产就绪功能非常有用。 非常好的和强大的属性和配置控件,您可以使用ap ...
-
在Spring Framework 5和Spring Boot 2中实例化服务器(Instantiating server in Spring Framework 5 and Spring Boot 2)[2023-03-14]
正如该文件所述 现在只剩下一个难题:在HTTP服务器上运行路由器功能。 您可以使用RouterFunctions.toHttpHandler(RouterFunction)将路由器功能转换为HttpHandler。 HttpHandler允许您运行各种反应运行时:Reactor Netty,RxNetty,Servlet 3.1+和Undertow。 这意味着你已经显示的上述代码,使用Reactor Netty作为反应运行时。 如果您希望使用其他具有反应式本机适配器的运行时,则可以这样做。 在这种情况下,你 ...