Spring Boot 替代索引页面

     2023-02-26     207

关键词:

【中文标题】Spring Boot 替代索引页面【英文标题】:Spring Boot alternative index page 【发布时间】:2015-04-20 13:07:56 【问题描述】:

我的应用在后端使用 Spring Boot,在前端使用 SPA (Angular) 站点。目前,我正在为webapp 文件夹中的 index.html 页面提供服务,该页面无需配置即可自动运行。现在我使用 gulp 为前端集成了一个构建过程,所有创建的源都被“复制”到一个 build 目录中。现在我想将build 目录中的index.html 文件作为我的主页。

我尝试了spring.application.index=build/index.html 和其他一些弹簧启动设置,但没有任何效果。我相信我当前的代码库不需要任何代码,但如果有任何遗漏,请告诉我。

有没有办法在applications.properties 文件中进行配置?我需要为索引页面创建一个控制器吗?或者有没有其他方法可以改变默认行为?

谢谢

【问题讨论】:

我们能否了解更多关于您的配置的信息 【参考方案1】:

通过common Spring Boot properties,你应该可以修改这个属性:

spring.application.index=

诚然,无论如何,我确实倾向于使用@RequestMapping("/") 创建一个最小的“家庭”控制器。 :)

值得注意的是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>

【讨论】:

我尝试了“/build/index.html”、“build/index.html”、“classpath:build/index.html”和其他一些版本,没有任何变化。我还尝试了来自 -***.com/questions/27836584/… 的建议解决方案。我将尝试使用“家庭”控制器。 好吧,家庭控制器工作了,我想我会离开那里,不会浪费时间去弄清楚为什么其他方式没有,谢谢。 我不确定它们是否是有用的替代品,但我添加了一些关于如何配置构建以将 Grunt 生成的资源移动到正确位置的选项。但是,如果控制器中的几行代码对您有用,那么正如您所说,可能不值得花太多时间进行实验。 Hrmm...您提供的链接没有对属性 spring.application.index 的任何引用?

索引页面不起作用,但 api 适用于 AWS beanstalk Spring Boot

】索引页面不起作用,但api适用于AWSbeanstalkSpringBoot【英文标题】:Indexpagedoesn\'tworkbutapiworksonAWSbeanstalkSprintBoot【发布时间】:2019-02-1919:06:42【问题描述】:我正在尝试将SpringBoot应用程序部署到aws。我通过application.properties将端口... 查看详情

在spring boot中实现自定义错误

】在springboot中实现自定义错误【英文标题】:Implementthecustomerrorinspringboot【发布时间】:2019-04-0702:58:26【问题描述】:我想页面。在应用程序中,id是主键,所以当没有给出id时,它会将请求传输到页面,但我希望应用程序在索... 查看详情

替代响应spring boot api rest

】替代响应springbootapirest【英文标题】:Alternativeresponsespringbootapirest【发布时间】:2020-02-2403:20:48【问题描述】:我是RESTAPI和SpringBoot的初学者。我对如何处理请求可能具有的不同响应有疑问。例如,如果我发布信用卡数据"number"... 查看详情

用于集成测试的 Spring Boot @LocalServerPort 的 DotNet 替代方案

】用于集成测试的SpringBoot@LocalServerPort的DotNet替代方案【英文标题】:DotNetalternativetospringboot@LocalServerPortforintegrationtests【发布时间】:2021-01-2719:16:08【问题描述】:我正在尝试测试DotNetCore应用程序的回调功能。我已经公开了我... 查看详情

Spring boot / mongo 不会使用索引注释创建索引

】Springboot/mongo不会使用索引注释创建索引【英文标题】:Springboot/mongowontcreateindexwiththeindexannotation【发布时间】:2019-03-3102:26:20【问题描述】:我有以下几点:@Document(collection="linkmetadata")publicclassLinkMetaData@Indexed(unique=true)privateStr... 查看详情

在 Kubernetes 中进行 Spring Boot 集成测试的 Testcontainers 的选项或替代方案?

】在Kubernetes中进行SpringBoot集成测试的Testcontainers的选项或替代方案?【英文标题】:OptionsoralternativestoTestcontainersforSpringBootintegrationtestinginKubernetes?【发布时间】:2021-12-1908:21:25【问题描述】:我需要使用Postgres、Redis和Elasticsearch... 查看详情

在 postgres spring-boot + eclipselink 中保存为 JSON 数据类型的替代解决方案

】在postgresspring-boot+eclipselink中保存为JSON数据类型的替代解决方案【英文标题】:AlternatesolutiontosaveasJSONdatatypeinpostgresspring-boot+eclipselink【发布时间】:2017-03-2009:50:00【问题描述】:我正在使用带有spring-bootJPA的eclipselink2.6来实现po... 查看详情

Spring Boot 索引未加载

】SpringBoot索引未加载【英文标题】:Springbootindexnotloading【发布时间】:2018-11-1122:55:04【问题描述】:我有一个SpringBoot应用程序。我没有使用@EnableWebMvc,我的资源位于src/main/resources/static文件夹中。当我尝试加载localhost:8080/ui/时... 查看详情

在spring boot / spring data elasticsearch中禁用自动索引创建

】在springboot/springdataelasticsearch中禁用自动索引创建【英文标题】:Disableautomaticindexcreationinspringboot/springdataelasticsearch【发布时间】:2017-12-1720:20:17【问题描述】:我想将创建索引(包括设置和映射)的过程与应用程序的其余部分... 查看详情

Spring Boot 2.3.0 - MongoDB 库不会自动创建索引

】SpringBoot2.3.0-MongoDB库不会自动创建索引【英文标题】:SpringBoot2.3.0-MongoDBLibrarydoesnotcreateindexesautomatically【发布时间】:2020-09-2406:26:23【问题描述】:我提供了一个示例项目来说明这个问题:https://github.com/nmarquesantos/spring-mongodb-r... 查看详情

使用 expireAfterSeconds 索引的 Spring Boot MongoDB 自动删除文档不起作用

】使用expireAfterSeconds索引的SpringBootMongoDB自动删除文档不起作用【英文标题】:SpringBootMongoDBIndexedwithexpireAfterSecondstoAutodeleteDocumentdoesnotwork【发布时间】:2018-11-0502:04:38【问题描述】:我对MongoDB中的“生存时间”设置有疑问。我... 查看详情

带有千分尺 Elasticsearch 注册表的 Spring Boot 仅索引空文档

】带有千分尺Elasticsearch注册表的SpringBoot仅索引空文档【英文标题】:SpringbootwithmicrometerElasticsearchregistryindexesonlyemptydocuments【发布时间】:2019-12-1701:02:36【问题描述】:我有一个简单的springboot2.1.7.RELEASE项目,使用micrometerElasticse... 查看详情

为啥必须对 Spring Boot 应用程序中的用户角色属性进行索引?

】为啥必须对SpringBoot应用程序中的用户角色属性进行索引?【英文标题】:WhytheUserroleattributeinSpringbootapphastobeindexed?为什么必须对SpringBoot应用程序中的用户角色属性进行索引?【发布时间】:2019-07-1707:22:23【问题描述】:我正... 查看详情

Spring Boot 项目显示登录页面

】SpringBoot项目显示登录页面【英文标题】:SpringBootprojectshowstheLoginpage【发布时间】:2018-02-2604:37:40【问题描述】:我用Springinitializer创建了一个Springboot项目,目前只有入门代码。示例代码@SpringBootApplicationpublicclassEcommerceApplicatio... 查看详情

Spring Boot Thymeleaf 缓存页面

】SpringBootThymeleaf缓存页面【英文标题】:SpringbootThymeleafCachepage【发布时间】:2017-12-1008:44:24【问题描述】:我实现了一个客户端应用程序。此应用程序使用Restweb服务,这些服务返回和html页面作为模型中的变量。我从RestService成... 查看详情

Spring Boot“不是实体”

】SpringBoot“不是实体”【英文标题】:SpringBoot"notanentity"【发布时间】:2019-03-1821:01:48【问题描述】:我是Hibernate和SpringBoot的新手。我的项目处理的搜索引擎由2个独立模块+1个共同的基本模块(IndexSetup类所在的位置)组... 查看详情

grails 3 spring security boot starter登录页面定制

】grails3springsecuritybootstarter登录页面定制【英文标题】:grails3springsecuritybootstarterloginpagecustomization【发布时间】:2016-05-0413:50:10【问题描述】:是否可以为入门安全插件自定义登录gsp页面?org.springframework.boot:spring-boot-starter-securit... 查看详情

spring boot 自定义登录页面

】springboot自定义登录页面【英文标题】:springbootcustomloginpage【发布时间】:2016-10-3112:01:44【问题描述】:我正在尝试为我的引导应用程序添加一个自定义登录页面。我正在关注this教程。我无法使用我的自定义登录页面。这是我... 查看详情