Spring 5 MVC Angular 5 App投掷404错误

古之立大事者,不惟有超世之才,亦必有坚忍不拔之志。这篇文章主要讲述Spring 5 MVC Angular 5 App投掷404错误相关的知识,希望能为你提供帮助。
我知道之前已经问过这个问题,我已经尝试了几种解决方案,但是无法正常工作。我正在使用Spring 5 MVC和/ src / main / webapp /中存在的角度应用程序。
该应用程序在访问基本路径时有效。当我需要跳进应用程序内的路线时,问题就来了。当页面尝试使用URL中的路由加载时,它会抛出404错误,因为Spring无法为此找到资源处理程序,但我真正希望它做的只是去应用程序的index.html这样有角度可以处理它。我试图在/ src / main / webapp /中的'app'文件夹中移动应用程序,你可以看到我在下面的资源处理程序和视图控制器。我使用swagger这个应用程序也使事情变得复杂。任何帮助,将不胜感激!

public class MvcConfiguration implements WebMvcConfigurer {...@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); registry.addResourceHandler("/app/**").addResourceLocations("/app/"); }@Override public void addViewControllers(ViewControllerRegistry registry) { registry.addRedirectViewController("/", "swagger-ui.html"); registry.addViewController("/swagger").setViewName("redirect:/rest/swagger-ui.html"); registry.addViewController("/app").setViewName("forward:/app/index.html"); }

以及下面的Web初始化类:
public class WebInitializer implements WebApplicationInitializer {AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); @Override public void onStartup(ServletContext container) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfiguration.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); registerDispatcherServlet(container, MvcConfiguration.class, "/views/*", "/rest/*", "/swagger/*"); container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false, "/*"); CharacterEncodingFilter charEncodingFilter = new CharacterEncodingFilter(); charEncodingFilter.setEncoding("UTF-8"); container.addFilter("encoding-filter", charEncodingFilter).addMappingForUrlPatterns(null, false, "/*"); container.addFilter("cors-filter", new CorsFilter()).addMappingForUrlPatterns(null, false, "/*"); }

答案【Spring 5 MVC Angular 5 App投掷404错误】您需要检查基本href属性。
< base href="https://www.songbingjia.com/src/main/webapp/">


    推荐阅读