sprintboot 构架详解

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_41876523/article/details/83784615

一、系统要求

1、Spring Boot 2.1.1.BUILD-SNAPSHOT需要Java 8,并且与Java 11兼容(包括在内)。 还需要Spring Framework 5.1.2.RELEASE或更高版本。需要maven3.3以上版本做构架支持

2、Servlet容器

tomcat 9.0    servlet 版本4。还可以将Spring Boot应用程序部署到任何Servlet 3.1+兼容容器。

3、使用spring boot前。需要查看jdk版本1.8以上才能使用

4、Spring Boot与Apache Maven 3.3或更高版本兼容。如果您还没有安装Maven。,可以按照maven.apache.org上的说明进行操作。

二、pom文件依赖

采用父类方式引入

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.1.0.RELEASE</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
</dependency>

三、测试代码

@RestController。这被称为 构造型注释。 它为阅读代码的人提供了提示。在spring传入web请求时会考虑这个

@RequestMapping注释提供“路由”的信息,任何带/路径的HTTP请求都应该映射到该home方法

@RestController@RequestMapping注解是Spring MVC的注解。(它们不是特定于Spring Boot的。

第二个类级注释是@EnableAutoConfiguration。这个注释告诉Spring Boot根据你添加的jar依赖关系“猜测”你想要如何配置Spring。自从spring-boot-starter-web添加了Tomcat和Spring MVC 以来,自动配置假定您正在开发Web应用程序并相应地设置Spring。

请注意,由于application.propertiesapplication.yml文件接受Spring样式占位符(${…​}),因此Maven过滤更改为使用@..@占位符。(您可以通过设置调用的Maven属性来覆盖它resource.delimiter。)

For instance, if you are running your application by using java -jar, you can enable the debug property as follows:

jar包测试bug
$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug

四、注解

猜你喜欢

转载自blog.csdn.net/weixin_41876523/article/details/83784615
今日推荐