Lau*_*nzo 3 thymeleaf spring-boot netbeans-8
Spring Boot 1.3引入了spring-boot-devtools来提供与Spring Reloaded类似的功能,以重新加载修改后的类并更新Thymeleaf模板,而无需重新运行您的应用程序.
之前我一直在使用Spring Boot 1.2.7(使用Spring Reloaded),我可以动态修改模板而无需重新启动Spring Boot应用程序.
当我修改和保存Java代码/ Thymeleaf模板时,相同的应用程序现在既不重新加载Thymeleaf模板也不重新加载/重新启动应用程序.
我正在使用嵌入在Netbeans IDE中的Netbeans 8.0.2和Maven(3.0.5版).该应用程序打包为JAR.
在Netbeans中,在项目属性 - >构建 - >编译下,勾选了一个"编译保存"复选框.我通过修改.java文件并检查/ target/classes中的时间戳来验证这实际上是有效的.
以下是Netbeans中项目的 "运行操作"属性:
我的pom.xml中有以下依赖项(包括其他因不相关而被排除在外):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
有了这个,我应该开始了,因为Spring Boot Blog提到了以下内容:
"如果包含spring-boot-devtools模块,任何类路径文件更改都将自动触发应用程序重启."
并在Spring Boot官方文档中做了类似的评论.
编辑:我尝试使用带有版本标签1.2.7.RELEASE的spring-boot-maven-plugin,并在保存模板时在浏览器中显示我的Thymeleaf模板的突然变化.看来至少Thymeleaf模板的问题不是因为spring-boot-devtools,而是因为spring-bot-maven-plugin.
问题可分为两部分:
1)如果使用较新版本的spring-boot-maven-plugin,则不会因某种原因重新加载的Thymeleaf模板(1.3.0.RELEASE)2)即使.class文件中也不会发生应用程序重载/重启触发器/ target/classes在修改和保存相应的.java文件时得到更新.
更新:已验证未加载devtools(主线程名称未重新启动).解决2)通过将Netbeans项目属性中的运行项目操作中的执行目标更改为以下内容:
process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
Run Code Online (Sandbox Code Playgroud)
旧的执行目标是package spring-boot:run.谷歌搜索显示其他人在使用spring-boot:run运行项目时遇到spring-boot-devtools问题.
现在唯一的问题是Thymeleaf模板在保存时不会实时更新.
将Netbeans项目属性中的"运行项目操作"中的"执行"目标更改为以下内容:
process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
而不是package spring-boot:run启用Spring Boot Devtools并重新启动按预期工作.
Thymeleaf模板的问题归因于这样一个事实:在Spring Boot 1.3中,Spring Boot Maven插件不再将src/main/resources直接添加到类路径中.有关详情,请参阅发行说明
将显式资源目录位置(在我的情况下为src/main/resources)配置为pom.xml解决了Thymeleaf模板无法重新加载的问题:
<build>
...
<resources>
<resource>
<directory> src/main/resources </directory>
</resource>
</resources>
...
</build>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1929 次 |
| 最近记录: |