每次运行时都会收到以下错误 mvn clean install
:“无法访问com.ludiaz.template。”
错误消息
在我切换电脑并在ubuntu20.04上重新下载intellij之后,其他项目也会出现这个错误。我已经检查了我所有的类是否都设置为public并单击了 Invalidate Caches/Restart
无数次。
这是产生上述错误的程序的项目结构:项目结构。它只是一个简单的spring初始化程序,在控制器中只有一个函数返回“hello”
编辑:
这是我的pom.xml文件:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ludiaz</groupId>
<artifactId>template</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>template</name>
<description>Template made with Spring Initializr</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
templateapplication.java:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TemplateApplication {
public static void main(String[] args) {
SpringApplication.run(TemplateApplication.class, args);
}
}
democontroller.java文件
package com.ludiaz.template.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@Controller
public class DemoController {
@ResponseBody
@GetMapping("/demo")
public String demo() {
return "Hello Demo";
}
}
1条答案
按热度按时间vawmfj5a1#
似乎我的一些spring依赖关系被破坏了。我只是删除了我的
/home/.m2
文件夹并重新生成项目。