Bar*_*rry 5 spring spring-mvc spring-boot
我遇到了这个问题,因为我有一个具有宁静服务的应用程序,但我也需要提供一些静态服务。在这个应用程序中,我也使用了EnableSwagger2注释。看起来这个类是公共的,我可以对它进行子类化,但我不确定如何配置它。我的目标是覆盖这条线,这样我就可以控制 404。
所以我终于做到了这一点,它对我来说很成功。配置让我有点,但在这里。假设您ResourceHttpRequestHandler使用名为CustomResourceHandler. 在我Application.java这把它正确地连接起来:
@Bean
public ResourceHttpRequestHandler resourceHttpRequestHandler() {
ResourceHttpRequestHandler requestHandler = new CustomResourceHandler();
requestHandler.setLocations(Arrays.<Resource>asList(applicationContext.getResource("/")));
return requestHandler;
}
@Bean
public SimpleUrlHandlerMapping sampleServletMapping(){
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setOrder(Integer.MAX_VALUE - 2);
Properties urlProperties = new Properties();
urlProperties.put("/**", "resourceHttpRequestHandler");
mapping.setMappings(urlProperties);
return mapping;
}
@Autowired
ApplicationContext applicationContext;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3427 次 |
| 最近记录: |