【发布时间】:2017-02-22 18:47:26
【问题描述】:
我正在开发一个使用 HTML 和 Thymeleaf 作为前端的 Java Spring Boot Web 应用程序。我遇到的问题是,当我尝试运行我的项目时,我的 ThymeleafConfig 类会随机出现错误。我将在下面更详细地解释,但首先是我的代码。
Pom.xml 依赖:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
ThymeleafConfig 类:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;
@Configuration
public class ThymeleafConfig {
@Bean
public SpringSecurityDialect springSecurityDialect() {
return new SpringSecurityDialect();
}
}
所以为了进一步解释,我的代码会很好(根据我的 IDE),我的任何行都没有错误,可以运行。我将运行我的应用程序类来运行我的项目,我会得到编译错误。
IntelliJ 会自动打开包含错误的文件,即我的ThymeleafConfig 类。出现错误时,导入语句import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect; 行将显示为灰色且无法识别。导致类中的错误。
要修复它,我右键单击我的 pom.xml 文件 -> Maven -> 重新导入。这将重新导入我的所有依赖项,一切都会恢复正常。
我还想强调,并非每次运行应用程序时都会发生这种情况。有时它会连续发生 3 次,有时我会运行它 5 次以上,然后才会再次出现错误。
我尝试了mvn clean,但没有解决问题。我还将依赖项移动到 pom.xml 文件中的不同行。
编辑: 这是我的 Application.java 类
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
要运行应用程序,我右键单击此文件并单击运行“应用程序”按钮。
【问题讨论】:
-
能否请您告诉我们您是如何构建/运行您的应用程序的?在我看来,您以某种方式删除了库/破坏了类路径。
-
当然 - 见编辑
-
我的 pom.xml 中有 15 个以上的其他依赖项 - 都按应有的方式运行。只是这个 Thymeleaf-security-4 依赖有问题
标签: java maven spring-boot intellij-idea dependencies