我在 Spring 中创建了一个简单的 Maven Web 应用程序,用于测试密码的强度并将其保存到 MySQL 数据库。然后我将其更改为 Spring Boot,以便我可以将其上传到 Heroku。 两个版本都在 localhost:8080 上运行良好,但是当我将 Spring Boot 版本上传到 Heroku 时,它看不到 CSS 文件,也看不到包含我用来查明密码是否包含任何现有单词的单词列表的文本文件。英语。 这是我在 Heroku 上的应用程序的链接 https://passwords2.herokuapp.com 正如您所看到的,没有背景或字体颜色,并且当它尝试查找单词列表“english.txt”文件时就会出现错误。 以下是 Git 中心的链接:https://github.com/PiotrDawidziuk/passwords2 唯一的区别是在 Heroku 版本中我将数据库选项更改为
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
在 application.properties 中,我添加了 PostgreSQL 的 Maven 依赖项。 image that shows what files I think Heroku doesn't see
编辑:我使用本教程将我的应用程序部署到 Heroku:https://www.youtube.com/watch?v=7RHYDNSRSOs
最佳答案
您的 english.txt
将放入 JAR 中,在 Heroku 中运行时,您的文件将位于 JAR 中,因此请尝试将其作为流读取,请检查 37233069查看如何以流的形式读取文件。同样在SpringBoot应用程序中,您不需要WEB-INF
内的resources
文件夹,在src\main\resources内创建
并将 css
文件夹\staticstylesheet.css
文件复制到此 css
文件夹。在jsps中,包含stylesheet.css
,如下所示
<link rel="stylesheet" href="/css/stylesheet.css">
关于java - Heroku 在 Spring Boot 中看不到 CSS 和静态 txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50631388/