8

前瞻:Spring 6.0 M1发布,将停止支持Freemarker和JSP

 2 years ago
source link: https://blog.didispace.com/spring-framework-6-0-M1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

前瞻:Spring 6.0 M1发布,将停止支持Freemarker和JSP

Spring Framework 6.0 第一个里程碑版本已经发布,目前已经可以从Spring Repo获取。这里有一些新变更我们可以提前了解一下。请大家踊跃留言、点赞、转发、再看。

Java EE迁移

甲骨文已经把Java EE捐献给Eclipse基金会数年了。Java EE的名称也变更为了Jarkarta EE,包名也相应地从javax变更为jakarta。例如javax.persistence现在对应为jakarta.persistence

在本次里程碑版本中涉及到的两个核心容器规范JSR-250JSR-330的包名都会迁移到Jakarta EE

Jakarta EE的持久层规范也将在此次里程碑版本中完成迁移。这意味着javax.persistencejakarta.validation都将实装。对应 Hibernate ORM 5.6.xHibernate Validator 7.0.x

如果您学习过程中如遇困难?可以加入我们超高质量的Spring技术交流群,参与交流与讨论,更好的学习与进步!更多Spring Boot教程可以点击直达!,欢迎收藏与转发支持!

Web 应用

Servlet中间件基准线

由于Jakarta EE的合并迁移,Servlet中间件也要进行升级。Tomcat 10, Jetty 11, 或者基于undertow-servlet-jakartaUndertow 2.2.14 是目前里程碑版本的基准线。

进一步移除过时API

一些过时的基于Servlet的组件已经在本次里程碑版本中移除。

  • Commons FileUpload 上传组件已经被移除。
  • 相关的前后端模板Tiles布局组件例如FreeMarkerJSP停止了支持。现在Spring将精力放在了基于RestfulWeb架构。

Controller扫描机制变动

现在Spring MVCSpring WebFlux将不再将类上单独有@RequestMappingSpring Bean视为控制器。在6.0之前默认情况以下代码是可以的:

/**
* 6.0之前
* @author felord.cn
*/
@Component
@RequestMapping("/foo")
public class FooController {

@GetMapping("/hello")
public Map<String, String> hello() {
return Collections.singletonMap("hello", "world");
}

}

6.0之前相关基于AOP的代理机制将失效, 请为此类控制器启用基于类的代理 。

6.0之后默认情况下必须有@Controller@RestController注解才可以被视为控制器。

HttpMethod

请求方法HttpMethod6.0之前为Java枚举。

/**
* 6.0 之前
*
* @since 3.0
*/
public enum HttpMethod {

GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;

private static final Map<String, HttpMethod> mappings = new HashMap<>(16);

static {
for (HttpMethod httpMethod : values()) {
mappings.put(httpMethod.name(), httpMethod);
}
}

@Nullable
public static HttpMethod resolve(@Nullable String method) {
return (method != null ? mappings.get(method) : null);
}

public boolean matches(String method) {
return name().equals(method);
}

}

6.0以后改为Java类:

public final class HttpMethod implements Comparable<HttpMethod>, Serializable {

private static final long serialVersionUID = -70133475680645360L;

private static final HttpMethod[] values;

private static final Map<String, HttpMethod> mappings = new HashMap<>(16);

public static final HttpMethod GET = new HttpMethod("GET");

public static final HttpMethod HEAD = new HttpMethod("HEAD");

public static final HttpMethod POST = new HttpMethod("POST");

public static final HttpMethod PUT = new HttpMethod("PUT");
// 其它省略
}

在2022年的1月份Spring Framework 6.0的第二个里程碑和对应的Spring Boot 3.0第一个里程碑将和大家见面。

好了,今天的学习就到这里!如果您学习过程中如遇困难?可以加入我们超高质量的Spring技术交流群,参与交流与讨论,更好的学习与进步!更多Spring Boot教程可以点击直达!,欢迎收藏与转发支持!

本文作者:码农小胖哥,
原文链接:https://mp.weixin.qq.com/s/G2an6b5jg329PudDGgTvOA
版权归作者所有,转载请注明作者、原文、译者等出处信息

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK