gpt4 book ai didi

java - Thymeleaf 依赖导致 Spring 工具套件中出现 "Error: Could not find or load main class"

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:15 27 4
gpt4 key购买 nike

我刚刚下载了 STS 并启动了一些 Maven 项目,它工作正常,但是当我开始使用 thymeleaf 时,它不起作用。

我在项目名称上看到一个感叹号,并且收到此错误错误:无法找到或加载主类

我尝试在 POM 中自行添加其依赖项,但出现该错误,一旦删除它们,该错误就会消失!

我还尝试创建一个“Spring Starter Project”并选择要添加的依赖项“Web and Thymeleaf”,在项目创建后,我在测试依赖项的 POM 中看到语法错误无法传输 org.springframework.boot:spring-boot-starter-test:jar

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

当我删除它及其类时,我得到了上面相同的错误。

现在这是我的 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo-2</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

最佳答案

尝试更新您的 Maven 存储库,首先尝试:

mvn dependency:purge-local-repository

Description:

When run on a project, remove the project dependencies from the local repository, and optionally re-resolve them. Outside of a project, remove the manually given dependencies.

然后尝试:

mvn dependency:copy-dependencies

Description:

Goal that copies the project dependencies from the repository to a defined location.

在我看来,您的本地 Maven 存储库不包含 thymeleaf 依赖项。

关于java - Thymeleaf 依赖导致 Spring 工具套件中出现 "Error: Could not find or load main class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43376840/

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