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

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第一个里程碑将和大家见面。你可以持续关注公众号: 码农小胖哥 获取一手消息。


原文:https://mp.weixin.qq.com/s/G2an6b5jg329PudDGgTvOA

1 个赞

mmp 跟不上学习了。