Мне трудно запустить свой сервер с помощью 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
My TaskController
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();
}
}
My ProgrammingLanguagesController:
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;
}
Мой пом. 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>