当我启动spring应用程序时,在自动configuration.the响应中发生异常,当我实现spring数据时,JPA如下所示
错误是
描述:
com.umn.documentfetching.documentcatching.DocumentLoader中的字段repositoryObject需要一个无法找到的'com.umn.documentfetching.repositorydata.DocumentLoaderRepository‘类型的bean。
操作:
考虑在配置中定义'com.umn.documentfetching.repositorydata.DocumentLoaderRepository‘类型的bean。
主
package com.umn.documentfetching;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.umn.documentfetching.entity.User;
import com.umn.documentfetching.repository.UserRepository;
import com.umn.documentfetching.service.dbUpdation;
@SpringBootApplication
public class DocumentFetchingWithHibernateApplication implements CommandLineRunner {
@Autowired
private dbUpdation dbUpdationObject;
public static void main(String[] args) {
SpringApplication.run(DocumentFetchingWithHibernateApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
User ob = new User();
ob.setEmail("ranjithayarotta@gmail.com");
ob.setId(1);
ob.setName("ranjith");
dbUpdationObject.inserdataintoDb(ob);
}
}dao类
package com.umn.documentfetching.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity // This tells Hibernate to make a table out of this class
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private String email;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}仓库类
package com.umn.documentfetching.repository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.umn.documentfetching.entity.User;
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
}服务类
package com.umn.documentfetching.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.umn.documentfetching.entity.User;
import com.umn.documentfetching.repository.UserRepository;
@Service
public class dbUpdation {
@Autowired
private UserRepository userRepoObect;
public void inserdataintoDb(User userData) {
userRepoObect.save(userData);
}
}这是我的属性文件
server.port=9891
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/Documentloader
spring.datasource.username=root
spring.datasource.password=careernow@123这是我的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>DocumentFetching</groupId>
<artifactId>documentFetchingWithHibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>documentFetchingWithHibernate</name>
<description>Load document store into the redis</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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-data-jpa</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
`发布于 2018-06-27 15:51:56
如下图所示,将Long改为Integer,然后尝试。
public interface UserRepository extends CrudRepository<User, Integer> {
}发布于 2018-06-27 20:23:47
我只是在我的项目中复制了你所有的类并运行它。它非常有效。
从我的数据库


错误说明了一切。您需要定义DocumentLoaderRepository。
https://stackoverflow.com/questions/51065812
复制相似问题