从静态文件夹中的Spring Boot应用加载多个Angular应用

时间:2019-07-15 19:20:34

标签: angular spring-boot

我有一个SpringBoot应用程序,它在静态文件夹中有一个角度应用程序,效果很好,现在我要在静态文件夹中添加一个应用程序,作为static / app2 /。当我尝试访问app2的index.html时,其他资源未加载并显示404错误,我按照下面的链接为我的角度项目返回了静态文件。

https://keepgrowing.in/java/springboot/make-spring-boot-surrender-routing-control-to-angular/#comment-129

任何帮助将不胜感激。

我已添加

 registry.addResourceHandler("/app2/**")
                .addResourceLocations("classpath:/static/app2/")
                .resourceChain(true)
                .addResolver(new PathResourceResolver() {
                    @Override
                    protected Resource getResource(String resourcePath, Resource location) throws IOException {
                        Resource requestedResource = location.createRelative(resourcePath);

                        return requestedResource.exists() && requestedResource.isReadable() ? requestedResource
                                : new ClassPathResource("/static/app2/index.html");
                    }
                });
    }

虽然仅调试对index.html的调用即将到来,但对脚本的其他调用却没有发生。

index.html是带有html标签(如<html> <script type="text/javascript" src="filename.js"></script></html>)内的脚本的angular应用的正常index.html。

和脚本位于app2的根目录中。 如果我从浏览器访问脚本,它将在浏览器中加载,例如: “本地主机:8080 / app2 / filename.js”。 但是访问localhost:8080 / app2 / index.html时。 在开发人员工具中,它将所有脚本调用显示为404。

0 个答案:

没有答案