gpt4 book ai didi

gradle - 一个Gradle Thymeleaf项目根据资源变更重新加载,另一个重新启动

转载 作者:行者123 更新时间:2023-12-03 04:01:09 28 4
gpt4 key购买 nike

编辑:我已经缩小了行为范围,不确定是否有一种方法可以完成我所需要的。

事实证明,我的应用在源代码树中将Thymeleaf模板下移了一层:

src/main/resources/tools-server/templates

然后在我的 tools-server.yml文件中进行设置,该文件会在应用程序启动时显式加载。从我的配置中删除该规范,并将 templates目录上移至
src/main/resources/templates

允许 spring-boot-devtools简单地重新加载模板,而无需重新启动应用程序。我认为除非有解决办法,否则我将向该项目提交错误。

我仍然很喜欢Spring Boot,所以请耐心等待。在过去的几个月中,我创建了两个项目,每个项目都从在线找到的不同示例开始。

关于重新加载Thymeleaf模板,第一个项目在更改模板时会巧妙地执行此操作,在模板更改时会发出两个日志消息,仅此而已。另一个执行应用程序的完全停止和重新启动,这会导致问题,因为它会重新创建临时安全密码(还需要更长的时间)。

这两个 gradle.build文件几乎相同,但依赖关系略有不同。我不确定这些差异是否会导致不同的行为。

工作之一:
buildscript
{
ext
{
springBootVersion = "1.4.3.RELEASE"
}
repositories
{
mavenCentral()
}
dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath group: "com.layer", name: "gradle-git-repo-plugin", version: "2.0.2"
}
}

apply plugin: "git-repo"
apply plugin: "java"
apply plugin: "maven"
apply plugin: "spring-boot"

jar
{
baseName = "HOA"
version = "0.0.1-SNAPSHOT"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories
{
mavenCentral()
maven { url "https://maven.atlassian.com/3rdparty/" }
maven { url "https://mvnrepository.com/artifact/" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}


dependencies
{
compile group: "org.mindrot", name: "jbcrypt", version: "0.4-atlassian-1"
compile group: "org.eclipse.persistence", name: "javax.persistence", version: "2.1.1"
compile group: "org.springframework.data", name: "spring-data-jpa", version: "1.10.4.RELEASE"
compile group: "org.springframework.hateoas", name: "spring-hateoas", version: "0.21.0.RELEASE"

compile group: "com.h2database", name: "h2", version: "1.4.192"

compile("org.springframework.boot:spring-boot-devtools")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-groovy-templates")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-web")

// Automated Testing

testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc")
}

dependencyManagement
{
imports
{
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR1"
}
}


compileJava
{
options.compilerArgs << "-Xlint:all" << "-Xdiags:verbose"
}

bootRepackage
{
mainClass = "com.latencyzero.hoa.Application"
}

bootRun
{
addResources = true
}

凌乱的一个:
buildscript
{
ext
{
springBootVersion = '1.4.3.RELEASE'
}

repositories
{
mavenCentral()
}

dependencies
{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

archivesBaseName = 'toolcrib'

compileJava
{
options.compilerArgs << "-Xlint:all" << "-Xdiags:verbose"
}

jar
{
manifest
{
attributes 'Implementation-Title': 'ToolCrib',
'Implementation-Version': version
}
}

repositories
{
mavenCentral()
}

dependencyManagement
{
imports
{
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR3'
}
}

dependencies
{
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'

compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')

runtime('org.postgresql:postgresql')

testCompile('org.springframework.boot:spring-boot-starter-test')
}

springBoot
{
mainClass = "com.latencyzero.toolcrib.services.tools.ToolsServer"
}


bootRun
{
addResources = true
}

感谢您的见解!

最佳答案

你有a look to the documentation

By default changing resources in /META-INF/maven, /META-INF/resources, /resources, /static, /public or /templates will not trigger a restart but will trigger a live reload.





If you want to customize these exclusions you can use the spring.devtools.restart.exclude



还有 spring.devtools.restart.additional-exclude可添加更多排除项并保留默认值。对于您的情况,应在配置中添加以下内容:
spring.devtools.restart.additional-exclude=classpath:/tools-server/templates/ 

关于gradle - 一个Gradle Thymeleaf项目根据资源变更重新加载,另一个重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455936/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com