gpt4 book ai didi

javascript - angular2 spring-boot项目结构

转载 作者:太空狗 更新时间:2023-10-29 17:55:02 26 4
gpt4 key购买 nike

我有一个新的 angular2 项目,它是使用快速入门中描述的标准文件结构构建的。我正在尝试构建一个 API 网关并让 spring-boot 托管我的应用程序,但是我无法将引导配置为使用我的项目中创建生成源的/dist 目录。项目结构如下:

project  
|--dist
|--node_modules
|--src
| |--app
| |--assets
| |--main
| | |--java
| | |--resources
| | | |--config
| | |--webapp
| | | |--WEB-INF

我想使用默认的/dist 目录,这样我仍然可以使用 npm/webpack 在 UI 上进行持续开发。

我试过像这样配置静态资源目录:

 spring.resources.staticLocations: /dist

但这似乎不起作用。

我创建了一个资源处理程序来直接指向 dist 目录:

@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {

String currentPath = new File("./").getAbsolutePath();
currentPath = "file:///" + currentPath;

registry.addResourceHandler("/**").addResourceLocations(currentPath + "/dist/");
}
}

这解决了部分问题,但现在我的根 URL ('/') 不再映射到 index.html。

是否有更简单/更好的方法来配置 spring-boot 以查找/dist 项目目录?我的项目结构应该改变吗?我真的很想让所有这些部分干净利索地协同工作。

最佳答案

Spring Boot会自动添加静态web资源位于以下任何目录中:

/META-INF/resources/

/resources/

/static/

/public/

文件夹是相对于src/main/resources

如果你像下面这样放置 index.html,那么 spring 可以提供你的文件无需任何配置。

src/main/resources/META-INF/resources/index.html

src/main/resources/resources/index.html

src/main/resources/static/index.html

src/main/resources/public/index.html

关于javascript - angular2 spring-boot项目结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39946536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com