spring - 如何使用 Spring Boot 从 tomcat 服务器部署 html

标签 spring maven tomcat intellij-idea

所以,答案可能非常简单,但我似乎无法弄清楚。

我已经根据本教程设置了一个 REST 网络服务:https://spring.io/guides/gs/rest-service/并使用 postman 设置了 Requestmapping 和所有内容,最终工作如我所愿。

我正在本地设置我的站点,但是当我尝试使用 jquery 发送 get 请求时,我收到以下错误:Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

所以我明白问题是我正在尝试从 file://运行我的 html 并且解决方案是从 tomcat 服务器上的本地主机运行它并在另一个主题中找到这个答案:Deploying just HTML, CSS webpage to Tomcat

但是,我找不到这样的 webapps 文件夹,我假设这是因为我的 tomcat 服务器是使用 maven 和 springboot 部署的。那么我的html/js怎么部署到tomcat服务器上呢?

我正在使用 Mac 和 IntelliJ 工作。

最佳答案

在您的 spring boot 应用程序中,您可以将 index.html 文件放在 src/main/resources/static 目录中,应用程序将提供该文件。

您也可以尝试在 spring boot 中配置 CORS,参见 this answer链接。

关于spring - 如何使用 Spring Boot 从 tomcat 服务器部署 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44736295/

相关文章:

java - STS : Imported projects are showing compilation error with triangle symbol

java - 我可以让 Jenkins 每小时检查一次 SVN 是否有变化吗?

java - 将多个 Maven 项目组合成一场 war

session - Tomcat 是如何维护 session 完整性的?

tomcat - 如何在cpanel上部署grails war文件(支持tomcat)

java - 通过集成 Spring SAML(作为 SP)和 SimpleSAML(作为 IdP)转发错误

maven - PMD with Maven - 如何禁用规则集中的一个规则?

css - 如何将CSS添加到Vaadin/Maven元素中?

spring - 以 Spring Java 配置方式实例化 Camel 时对 BundleContextAware 的运行时依赖

spring 工具套件无法在 tomcat 上部署示例 Web 服务