我創建了一個 Spring Boot 應用程式,并在運行它時收到此警告。
2022-10-27 00:35:12.520 WARN 11512 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)
在這里,你可以看到我的 application.properties 檔案
spring.datasource.url=jdbc:mysql://localhost:3306/springbootblogapp?
createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
spring.jpa.open-in-view=false
盡管這里有一些相關的問題,但為他們提供的答案對我不起作用,因為那里提到的警告與我得到的警告有點偏離。
請幫我。
uj5u.com熱心網友回復:
我最初的評論,轉移到一個答案:
這是您的問題中顯示的警告訊息的文本:
2022-10-27 00:35:12.520 WARN 11512 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)
您是否嘗試過警告訊息的建議 - 例如,通過添加:
spring.thymeleaf.check-template-location=false
到您的應用程式的配置?或者通過創建templates警告訊息中提到的目錄(并在那里添加模板)?默認情況下,此目錄應在資源位置創建,因此它在運行時位于應用程式的類路徑中。
根據您的后續評論進行更新:
為什么會收到此警告?
創建 Spring Boot 應用程式時,可以選擇各種附加依賴項(例如使用Spring Initializr)。
Thymeleaf 就是這樣一種額外的依賴項。
對于 Maven(假設您使用的是 Maven),這是您 POM 中的以下工件:
<artifactId>spring-boot-starter-thymeleaf</artifactId>
如果您沒有設定要存盤 Thymeleaf 模板的基本位置,則選擇此選項毫無意義。
如果您選擇配置選項:
spring.thymeleaf.check-template-location=false
那么你告訴 Spring 不要去檢查你的 Thymeleaf 模板是否有一個有效的配置位置。
因此,即使沒有有效的配置位置,您也不會看到該警告。
如果您決定確實要使用 Thymeleaf,則需要通過templates在運行時類路徑上提供默認檔案夾或通過屬性檔案指定自定義位置來解決此問題。
您可能會看到與您選擇的其他 Spring Boot 依賴項類似的警告(甚至錯誤)。例如,如果您選擇包含 JDBC API,但沒有配置有效的資料源,那么我相信這會導致錯誤(如果我記得的話)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522035.html
下一篇:FeignExceptioncom.fasterxml.jackson.databind.exc.InvalidDefinitionException:無法構造`org.springframework
