当我在自动配置中启动spring boot应用程序异常时。下面给出了我实现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>
`