我们正在一个角度应用程序上运行一个Spring启动应用程序。在我们的设置中,我们将WebMvcConfigurerAdapter
子类化为分别从/app/**
,/assets/**
到/angular-app/app/
和/angular-app/assets/
的路线。我无法路由/error
以返回位于/angular-app/error.html
的页面。据我所知,实现这一目标应该通过实施InternalResourceViewResolver
。
我在启用了跟踪的情况下运行了应用程序,似乎对/angular-app/error.html
的GET请求返回了一个空模型和视图。我担心我们通过继承WebMvcConfigurerAdapter
来禁用某些功能,这对于让它像正常情况一样运行并提供来自/public
或/static
配置代码如下。
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
private static Logger log = Logger.getLogger(WebMvcConfiguration.class);
@Bean
public ViewResolver getViewResolver() {
log.info("configured view resolver");
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/angular-app/");
resolver.setSuffix(".html");
return resolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
registry.addViewController("/login/no-op").setViewName("forward:/no-op.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/app/**").addResourceLocations("classpath:/angular-app/app/");
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/angular-app/assets/");
registry.addResourceHandler("/fonts/**").addResourceLocations("classpath:/angular-app/fonts/");
registry.addResourceHandler("/maps/**").addResourceLocations("classpath:/angular-app/maps/");
registry.addResourceHandler("/scripts/**").addResourceLocations("classpath:/angular-app/scripts/");
registry.addResourceHandler("/styles/**").addResourceLocations("classpath:/angular-app/styles/");
registry.addResourceHandler("/index.html").addResourceLocations("classpath:/angular-app/index.html");
registry.addResourceHandler("/no-op.html").addResourceLocations("classpath:/static/no-op.html");
registry.addResourceHandler("/**").addResourceLocations("classpath:/angular-app/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new AuthenticationPrincipalArgumentResolver());
}
}
在请求之后,我看到一条日志,说明请求被路由到正确的位置。
[INFO]::[2016-07-12 12:08:11.979 PM]::[ity.common.filter.LoggerFilter] <<<[GET][maadmin@maestroqa.com][UNKNOWN_IP]::/angular-app/error.html
我尝试将setAlwaysUseFullPath
用于true
,结果相同。
如果我能提供更多信息,请告诉我。