gpt4 book ai didi

java - 不推荐使用 WebMvcConfigurerAdapter 类型

转载 作者:IT老高 更新时间:2023-10-28 11:28:40 26 4
gpt4 key购买 nike

我只是迁移到 spring mvc 版本 5.0.1.RELEASE 但突然在 eclipse STS WebMvcConfigurerAdapter 被标记为已弃用

public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
// to serve static .html pages...
registry.addResourceHandler("/static/**").addResourceLocations("/resources/static/");
}
....
}

我怎样才能删除这个!

最佳答案

从Spring 5开始你只需要实现接口(interface)WebMvcConfigurer:

public class MvcConfig implements WebMvcConfigurer {

这是因为 Java 8 在接口(interface)上引入了默认方法,这些方法涵盖了 WebMvcConfigurerAdapter 类的功能

看这里:

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/WebMvcConfigurerAdapter.html

关于java - 不推荐使用 WebMvcConfigurerAdapter 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47552835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com