创建名称为“ methodValidationPostProcessor”的豆时出错

时间:2019-01-11 10:24:28

标签: java spring hibernate maven spring-boot

我是sprnig引导的新手。 我在IntelliJ IDEA 2018上使用Spring Boot创建了一个带有spring boot initiliazr的项目。

当我尝试运行项目时,由于methodValidationPostProcessor而出现异常。

POM:

    <?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>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>projetsm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projetsm</name>
<description>Demo project for Spring Boot</description>

<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-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</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</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>net.postgis</groupId>
        <artifactId>postgis-jdbc</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency> <groupId>org.hibernate</groupId>
        <artifactId>hibernate-agroal</artifactId>
        <version>5.4.0.Final</version> <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>javax.persistence-api</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>5.4.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>5.1.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.0.0.RELEASE</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

错误日志:

  

启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。   2019-01-11 10:49:43.950错误18920 --- [main] o.s.boot.SpringApplication:应用程序运行失败   org。嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'incidentRepository'的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定index / type / name参数以避免类型歧义)       在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:228)〜[spring-context-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)〜[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]       在com.example.projetsm.ProjetsmApplication.main(ProjetsmApplication.java:31)上[classes /:na]   原因:org.springframework.beans.factory.BeanCreationException:创建名称为'incidentRepository'的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定index / type / name参数以避免类型歧义)       在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:268)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:974)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:848)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:514)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:477)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeInIncludeAncestors(BeanFactoryUtils.java:227)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1401)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1200)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]       在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE]       ... 19个通用框架

Incident.java

package com.example.projetsm.Entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Entity
@Table(name="Incident")
public class Incident implements Serializable {

  @Id
  private long idIncident;
  @NotNull
  @Column(name = "titre")
  private String titre;
  @Column (name = "secteur")
  private String secteur;
  @Column (name = "description")
  private String description;
  @Column (name = "date")
  private String date_inc;
  @Column (name = "geom", columnDefinition = "geometry")
  private String geom;

  public Incident(){}
  public Incident(@NotNull String titre, @NotNull String secteur, @NotNull String description){
  this.titre=titre;
  this.secteur=secteur;
  this.description=description;}
  public Incident(@NotNull String titre, @NotNull String secteur, @NotNull String description, @NotNull String geom){
  this.titre=titre;
  this.secteur=secteur;
  this.description=description;
  this.geom=geom;}

  public long getIdIncident() {
return idIncident;}

 public void setIdIncident(long idIncident) {
this.idIncident = idIncident;}

  public String getTitre() {
return titre;}

  public void setTitre(String titre) {this.titre = titre;}


  public String getSecteur() {
return secteur;}

  public void setSecteur(String secteur) {
this.secteur = secteur;}


  public String getDescription() { return description;}

  public void setDescription(String description) {this.description = description;}


  public String getDate_inc() {
return date_inc;}

  public void setDate_inc(String date) {this.date_inc = date_inc;}


  public String getGeom() {
return geom;}

  public void setGeom(String geom) {
this.geom = geom;}
}

IncidentController:

package com.example.projetsm.Controller;
import com.example.projetsm.Entities.Incident;

import com.example.projetsm.Repositories.IncidentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
@RequestMapping("/incident")
@CrossOrigin("*")

public class IncidentController {

@Autowired
private IncidentRepository incidentRepo;

@Autowired
public IncidentController(IncidentRepository incidentRepo) {
    this.incidentRepo = incidentRepo;
}

@RequestMapping(value = "/saveIncident", method = RequestMethod.POST)
private Incident saveIncident(Incident incident){
    return incidentRepo.save(incident);
}

@RequestMapping(value = "/listIncident",method = RequestMethod.GET)
private Page<Incident> listPageIncident(
        @RequestParam(name = "page",defaultValue = "0")int page,
        @RequestParam(name = "size",defaultValue = "5")int size
){
    return incidentRepo.listIncident(PageRequest.of(page,size));
}

}

IncidentRepository:

package com.example.projetsm.Repositories;

import com.example.projetsm.Entities.Incident;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.List;

@Transactional
@Repository
public interface IncidentRepository extends JpaRepository<Incident,Integer> {

@Modifying
@Query(value = "INSERT INTO Incident" +
        "(id_incident, titre, secteur, geom," +
        "description,date) " +
        "VALUES( :idIncident,:titre,:secteur ,ST_SetSRID(ST_Point(:lng,:lat),4326)," +
        ":desciption,:date_inc)"
        , nativeQuery = true)
public void saveIncident(
        @Param("idIncident") Long idIncident,@Param("titre") String titre,
        @Param("secteur") String secteur,@Param("description") String description,
        @Param("lng") Double lng, @Param("lat") Double lat,
        @Param("date_inc") String date_inc
);

@Query(value = "SELECT * FROM public.incident ORDER BY id_laureat ASC " , nativeQuery = true)
public Page<Incident> listIncident(Pageable pageable);

@Query(value = "SELCET ST_X(geom), ST_Y(geom), id_incident, titre, secteur, description, date_inc FROM public.incident ORDER BY id_incident ASC", nativeQuery = true)
public List<Object> listActivityincident();

@Query(value = "SELECT ST_X(geom), ST_Y(geom),id_incident,titre, secteur, description," +
        "date_inc FROM public.incident WHERE id_incident=:id" , nativeQuery = true)
public Object listActivityIncidentID(@Param("id")  Long idIncident);

@Query(value = "SELECT COUNT(id_incident) FROM incident" , nativeQuery = true)
public int countID();
@Query(value = "SELECT * FROM laureat where id_laureat=:id" , nativeQuery = true)
public Incident findIncidentBy(@Param("id")  int idIncident);

}

我看了这个问题,并且发现了一些关于这个问题的建议。我已经尝试在POM上添加hibernate-validator的另一个版本,但是错误仍然存​​在,以添加和删除spring-boot-starter-web等。

如果有人可以帮助我,我将不胜感激。

0 个答案:

没有答案