+-

我只是迁移到 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开始,您只需要实现WebMvcConfigurer接口:
public class MvcConfig implements WebMvcConfigurer {
这是因为Java 8在接口上引入了默认方法,这些方法涵盖了WebMvcConfigurerAdapter类的功能
看这里:
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/WebMvcConfigurerAdapter.html
点击查看更多相关文章
转载注明原文:java – 不推荐使用WebMvcConfigurerAdapter类型 - 乐贴网