我是Spring Boot的新手,当我按照Spring指南访问数据时,我遇到了这个问题
我的STS IDE出错,我不知道到底发生了什么。
在src/main/java/UserRepository.java
package hello;
import org.springframework.data.repository.CrudRepository;
import hello.User;
public interface UserRepository extends CrudRepository<User, Long> {
}
STS警告我这个错误,我忽略它直到我运行Cmd: mvn spring-boot
所以我回来检查警告,它是:
The type org.springframework.data.repository.Repository cannot be
resolved. It is indirectly referenced from required .class files
非常感谢帮助我!
我按照建议使用Maven来构建项目,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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-mysql-data</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
答案 0 :(得分:0)
将一些Spring引导标准应用于代码
将您的启动应用程序保留在程序包之上,在您的情况下,您的BootApplication应该在hello程序包中。如下图所示
@SpringBootApplication
public class BootApplication extends SpringBootServletInitializer {
public static void main(String args[]) {
SpringApplication.run(BootApplication.class, args);
}
}
现在将您的存储库保存在hello的子包中。在你的情况下,它应该在hello.repository
现在尝试使用BootApplication运行。
答案 1 :(得分:0)
现在我的项目与[gs-access-data-mysql-complete]
完全相同Spring官方网站认为这是一个成功的项目,让教练检查[gs-access-data-mysql-initial]对[gs-access-data-mysql-complete] .Hower,甚至后者都无法成功构建。我的项目结构:
src
+main
+java
+hello
--Application.java
--MainController.java
--User.java
--UserRepository.java
和日志信息,我最好向您展示摘要: 1. [错误]无法执行目标org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:在项目gs-mysql-data上运行(default-cli):运行时发生异常。 null:InvocationTargetException:在文件[D:\ workbunch \ Spring Workbunch \ gs-acces-data-mysql-initial \ target \ classes \ hello \ MainController.class]中定义名称为'mainController'的bean时出错:合并的后处理bean定义失败;嵌套异常是java.lang.IllegalStateException:无法从ClassLoader [java.net.URLClassLoader@6424f2f4]内省Class [hello.MainController]:org / springframework / data / repository / CrudRepository:org.springframework.data.repository.CrudRepository - &GT; [帮助1]