我的应用程序在后端使用 Spring Boot,在前端使用 SPA (Angular) 站点。目前,我正在从 webapp
文件夹中提供 index.html 页面,无需配置即可自动运行。现在我使用 gulp 为前端集成了一个构建过程,所有创建的源都被“复制”到 build
目录中。现在我想将 build
目录中的 index.html
文件作为我的主页。
我尝试了 spring.application.index=build/index.html
和其他一些 spring boot 设置,但没有任何效果。我相信我当前的代码库中不需要任何代码,但如果有任何遗漏请告诉我。
有没有办法在 applications.properties
文件中配置它?我需要为索引页创建一个 Controller 吗?还是有其他方法可以更改默认行为?
谢谢
最佳答案
按照 common Spring Boot properties 进行,您应该能够修改此属性:
spring.application.index=
无可否认,无论如何,我确实倾向于使用 @RequestMapping("/")
创建一个最小的“主” Controller 。 :)
值得注意的是,build
目录只有在 src/main/resources
下才会出现在类路径中。还值得一提的是,src/main/webapp
的内容不会自动捆绑到 jar 中。 src/main/resources/static
是 Spring Boot 查找静态 Web 文件的地方。因此,您有多种选择。
选项 1:将 Grunt 构建配置为输出到 src/main/resources/static
下的目录。
选项 2:配置您的 Java 构建工具以获取 Grunt 输出并将其放入您的资源目录中,以便它位于类路径中。例如,使用 Maven,以下命令会将名为 build
的目录的内容移动到您的 src/main/rescources/static
中。
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>build</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
关于java - Spring Boot 替代索引页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28602131/