3
我遇到this issue,因为我有一个应用程序具有宁静的服务,但我需要提供一些静态的服务。在这个应用程序中,我也使用EnableSwagger2
注释。它看起来像这个类是公开的,我可以继承它,但我不知道如何配置它。我的目标是覆盖this line,所以我可以控制404s。春季启动可以用我自己的实现替换ResourceHttpRequestHandler吗?
我遇到this issue,因为我有一个应用程序具有宁静的服务,但我需要提供一些静态的服务。在这个应用程序中,我也使用EnableSwagger2
注释。它看起来像这个类是公开的,我可以继承它,但我不知道如何配置它。我的目标是覆盖this line,所以我可以控制404s。春季启动可以用我自己的实现替换ResourceHttpRequestHandler吗?
所以我终于做到了这一点,它为我成功地工作。配置让我稍微有一点,但在这里。假设您将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;
原来正常工作100%。 – Barry