Spring 引导备用索引页
Spring Boot alternative index page
我的应用程序在后端使用 Spring 引导,在前端使用 SPA (Angular) 站点。目前我正在为 webapp
文件夹中的 index.html 页面提供服务,该页面自动运行,无需配置。现在我使用 gulp 为前端集成了一个构建过程,所有创建的源都 "copied" 到 build
目录中。现在我想将 build
目录中的 index.html
文件作为我的主页。
我尝试了 spring.application.index=build/index.html
和其他一些 spring 引导设置,但没有任何效果。我相信我当前的代码库不需要任何代码,但如果有任何遗漏请告诉我。
有没有办法在 applications.properties
文件中进行配置?我需要为索引页创建一个控制器吗?还是有其他方法可以更改默认行为?
谢谢
按照 common Spring Boot properties,你应该可以修改这个 属性:
spring.application.index=
诚然,我确实倾向于创建一个带有 @RequestMapping("/")
的最小 'home' 控制器。 :)
值得注意的是 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>
我的应用程序在后端使用 Spring 引导,在前端使用 SPA (Angular) 站点。目前我正在为 webapp
文件夹中的 index.html 页面提供服务,该页面自动运行,无需配置。现在我使用 gulp 为前端集成了一个构建过程,所有创建的源都 "copied" 到 build
目录中。现在我想将 build
目录中的 index.html
文件作为我的主页。
我尝试了 spring.application.index=build/index.html
和其他一些 spring 引导设置,但没有任何效果。我相信我当前的代码库不需要任何代码,但如果有任何遗漏请告诉我。
有没有办法在 applications.properties
文件中进行配置?我需要为索引页创建一个控制器吗?还是有其他方法可以更改默认行为?
谢谢
按照 common Spring Boot properties,你应该可以修改这个 属性:
spring.application.index=
诚然,我确实倾向于创建一个带有 @RequestMapping("/")
的最小 'home' 控制器。 :)
值得注意的是 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>