我读了一篇题为 SPRING 3.1 M2: SPRING MVC ENHANCEMENTS 的博客文章可以替换 <resources mapping="/resources/**" location="/resources/" />
具有以下等价元素:
@Configuration
@EnableWebMvc
public class AppConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureResourceHandling(ResourceConfigurer configurer) {
configurer.addPathMapping("/resources/**").addResourceLocation("/resources/");
}
}
但是在 Spring 3.2.0.RELEASE 中我似乎找不到 ResourceConfigurer
。这个功能有没有正式发布过?我的依赖项可能有问题,但在发布所有内容之前我只想检查一下。
最佳答案
这个机制在 3.2 中被重新设计,几个月前我也遇到了同样的问题。现在你要做的就是重写一个不同的方法。尽管您可能需要使用路径等,但以下内容似乎对我有用:
@Configuration
@EnableWebMvc
public class AppConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/").addResourceLocations("/resources/**");
}
}
关于spring-mvc - Spring 3.2.0.RELEASE中的ResourceConfigurer去哪儿了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14245774/