繁体   English   中英

我为我的 spring 启动应用程序收到在 class 路径资源中定义的名称为 'requestMappingHandlerAdapter' 的创建 bean 时出错

[英]I get the 'Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource' for my spring boot application

我很难用 spring 来启动我的服务器。 我查找了与我类似的错误,这似乎与我使用 RequestMapping 的方式有关。 尽管尝试了各种方法来定义我的路线,但我仍然无法弄清楚似乎是什么问题。 有任何想法吗?

这是我的错误信息:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qualificationRepository' defined in com.salay.christophersalayportfolio.repositories.QualificationRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qualificationRepository' defined in com.salay.christophersalayportfolio.repositories.QualificationRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages

我的任务控制器

import com.salay.christophersalayportfolio.models.Task;
import com.salay.christophersalayportfolio.repositories.TaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping(path = "/api/v1/tasks")
public class TaskController {

    @Autowired
    private TaskRepository taskRepository;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public @ResponseBody String add(@RequestBody Task task) {
        taskRepository.save(task);
        return "Successfully saved the task to the database.";
    }

    @RequestMapping(value = "/{id/", method = RequestMethod.GET)
    public Task getById(@PathVariable int id){

        Optional<Task> task = taskRepository.findById(id);

        if(!task.isPresent()){
            throw new NullPointerException();
        }
        else {
            return task.get();
        }
    }

    @RequestMapping(value = "/all/", method = RequestMethod.GET)
    public List<Task> getAll() {
        return taskRepository.findAll();
    }

}

我的编程语言控制器:

package com.salay.christophersalayportfolio.controllers;

import com.salay.christophersalayportfolio.models.ProgrammingLanguage;
import com.salay.christophersalayportfolio.repositories.ProgrammingLanguageRepositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping(path = "/api/v1/programmingLanguages")
public class ProgrammingLanguageController {

    @Autowired
    private ProgrammingLanguageRepositories plRepository;

    @RequestMapping( value= "/add", method = RequestMethod.POST)
    public @ResponseBody String add(@RequestBody ProgrammingLanguage pl){
        plRepository.save(pl);
        return "This programming language has been successfully saved";
    }


    @RequestMapping( value = "/{id}/", method = RequestMethod.GET)
    public ProgrammingLanguage getById(@PathVariable int id){
        Optional<ProgrammingLanguage> pl = plRepository.findById(id);

        if( !pl.isPresent()){
            throw new NullPointerException();
        }
        else {
            return pl.get();
        }
    }

    @RequestMapping( value = "/all", method = RequestMethod.GET)
    public List<ProgrammingLanguage> getAll(){
        return plRepository.findAll();
    }
}

以下是我的实体:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class ProgrammingLanguage {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    public String name;
    public String image;
}
import javax.persistence.*;
import java.util.Set;

@Entity
public class Dissertation {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private int qualificationId;
    public String title;

    @OneToMany(mappedBy="dissertation")
    public Set<ProgrammingLanguage> programmingLanguages;
    public Set<Tool> tools;
}
package com.salay.christophersalayportfolio.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Task {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private int experienceId;
    private int projectId;
    public String description;
}
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Task {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private int experienceId;
    private int projectId;
    public String description;
}
import javax.persistence.*;
import java.util.Set;

@Entity
public class Project {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    public String name;
    public String description;
    public String client;

    @OneToMany(mappedBy = "project")
    public Set<ProgrammingLanguage> programmingLanguages;

    @OneToMany(mappedBy = "project")
    public Set<Tool> tools;

    @OneToMany(mappedBy = "project")
    public Set<String> images;

    @OneToMany(mappedBy = "project")
    public Set<Task> tasks;
}

我的 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.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.salay</groupId>
    <artifactId>christopher-salay-portfolio</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>christopher-salay-portfolio</name>
    <description>Back-end application for my portfolio</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</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-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.3.1.jre14-preview</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

问题不在您的请求映射中,由于实体映射中的问题,您的应用程序无法启动,请仔细检查您的映射,如错误中所述: mappedBy reference an unknown target entity

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages

您的 class com.salay.christophersalayportfolio.models.ProgrammingLanguage似乎没有名为dissertation的属性

否则,分享你的 model 来看看吧!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM