Spring Boot自动配置中的例外

时间:2018-06-27 14:50:09

标签: spring-mvc spring-boot spring-data-jpa

当我在自动配置中启动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>


            `

2 个答案:

答案 0 :(得分:0)

按如下所示将Long更改为Integer并尝试。

public interface UserRepository extends CrudRepository<User, Integer> {
}

答案 1 :(得分:0)

我刚刚在项目中复制了所有类并运行它。它可以完美地工作。

来自我的数据库

table1

table2

错误说明了一切。您需要定义df_train['cabin'][df_train['cabin'] != '0'] = 1