基于SpringBoot2.0版本与老版本的区别

网友投稿 257 2022-12-01

基于SpringBoot2.0版本与老版本的区别

目录SpringBoot版本问题这是maven依赖一、解决方案二、解决方案

SpringBoot2.0版本新特性

以java 8 为基准

Spring Boot 2.0 要求Java 版本必须8以上, Java 6 和 7 不再支持。

内嵌容器包结构调整

为了支持reactive使用场景,内嵌的容器包结构被重构了的幅度有点大。EmbeddedServletContainer被重命名为WebServer,并且org.springframework.boot.context.embedded 包被重定向到了org.springframework.boot.web.embedded包下。

举个例子,如果你要使用TomcatEmbeddedServletContainerFactory回调接口来自定义内嵌Tomcat容器,你现在应该使用TomcatServletWebServerFactory。

Servlet-specific 的server properties调整

大量的Servlet专属的server.* properties被移到了server.servlet下:

Old property

New property

server.context-parameters.*

server.servlet.context-parameters.*

server.context-path

server.servlet.context-path

server.jsp.class-name

server.servlet.jsp.class-name

server.jsp.init-parameters.*

server.servlet.jsp.init-parameters.*

server.jsp.registered

server.servlet.jsp.registered

server.servlet-path

server.servlet.path

由此可以看出一些端倪,那就是server不再是只有servlet了,还有其他的要加入。

Actuator 默认映射

ctuator的端点(endpoint)现在默认映射到/application,比如,/info 端点现在就是在/application/info。但你可以使用management.context-path来覆盖此默认值。

Spring Loaded不再支持

由于Spring Loaded项目已被移到了attic了,所以不再支持Spring Loaded了。现在建议你去使用Devtools。Spring Loaded不再支持了。

支持Quartz Scheduler

Spring Boot 2 针对Quartz调度器提供了支持。你可以加入spring-boot-starter-quartz starter来启用。而且支持基于内存和基于jdbc两种存储。

OAuth 2.0 支持

Spring Security OAuth 项目中的功能将会迁移到Spring Security中。将会OAuth 2.0。

支持Spring WebFlux

WebFlux 模块的名称是 spring-webflux,名称中的 Flux 来源于 Reactor 中的类 Flux。该模块中包含了对反应式 HTTP、服务器推送事件和 WebSocket 的客户端和服务器端的支持。

对于开发人员来说,比较重要的是服务器端的开发,这也是本文的重点。

在服务器端,WebFlux 支持两种不同的编程模型:第一种是 Spring MVC 中使用的基于 Java 注解的方式;第二种是基于 Java 8 的 lambda 表达式的函数式编程模型。这两种编程模型只是在代码编写方式上存在不同。

它们运行在同样的反应式底层架构之上,因此在运行时是相同的。

WebFlux 需要底层提供运行时的支持,WebFlux 可以运行在支持 Servlet 3.1 非阻塞 IO API 的 Servlet 容器上,或是其他异步运行时环境,如 Netty 和 Undertow。

版本要求

Jetty

要求Jetty最低版本为9.4。

Tomcat

要求Tomcat最低版本为8.5。

Hibernate

要求Hibernate最低版本为5.2。

Gradle

要求Gradle最低版本为3.4。

SendGrid

SendGrid最低支持版本是3.2。为了支持这次升级,username和password已经被干掉了。因为API key现在是唯一支持的认证方式。

SpringBoot版本问题

IDEA创建springboot中启动问题

Exception in thread “main” java.lang.AbstractMethodError:

org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

大家度知道这是一个springboot的启动类

这是maven依赖

<?xml version="1.0" encoding="UTF-8"?>

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.1.3.RELEASE

com.example

demo

0.0.1-SNAPSHOT

demo

Demo project for Spring Boot

1.8

org.springframework.boot

spring-boot-starter

spring-context

org.springframework

org.springframework.boot

spring-boot-starter-test

test

org.projectlombok

lombok

true

com.baomidou

mybatis-plus-boot-starter

3.1.0

com.h2database

h2

runtime

org.springframework

spring-context

4.3.2.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-maven-plugin

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.1.3.RELEASE

com.example

demo

0.0.1-SNAPSHOT

demo

Demo project for Spring Boot

1.8

org.springframework.boot

spring-boot-starter

spring-context

org.springframework

org.springframework.boot

spring-boot-starter-test

test

org.projectlombok

lombok

true

com.baomidou

mybatis-plus-boot-starter

3.1.0

com.h2database

h2

runtime

org.springframework

spring-context

4.3.2.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-maven-plugin

看起来万事俱备,也很符合springboot启动需要,那就启动吧

Exception in thread "main" java.lang.AbstractMethodError:

org.springframewohttp://rk.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

结果给http://你抛出这样的异常

此时不慌,原因有两个(我所能想到的,不喜勿喷)

jar冲突

springboot的版本问题

一、解决方案

在IDEA中下载maven helper插件,方便排查jar冲突,

重启后的点击pom会出现Dependency Analyzer

排查冲突后再次运行程序,出现如下情况

二、解决方案

像魔鬼一样还是没有解决,这时候疯狂的上百度搜,依然没有找到办法解决,最后在拉屎的瞬间想到springboot 有一个 1.5.6的版本,出于好奇将2.1.3版本修改为1.5.6版本如下

org.springframework.boot

spring-boot-starter-parent

1.5.6.RELEASE

看到下面的图,恭喜你,springboot启动成功

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:MYS-6ULX-IOT 开发板测评——Yocto 创建嵌入式 Linux 发行版
下一篇:Python春节特训营01:和电脑做朋友
相关文章

 发表评论

暂时没有评论,来抢沙发吧~