无法启动maven项目。自动装配失败并且创建DTO bean失败

时间:2017-07-24 13:48:06

标签: spring maven exception autowired

Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grupaDTOToGrupa': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.service.GrupaService jwd.festival.support.GrupaDTOToGrupa.grupaService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaGrupaService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.repository.GrupaRepository jwd.festival.service.impl.JpaGrupaService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grupaRepository': Cannot create inner bean '(inner bean)#1cd201a8' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1cd201a8': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'igracDTOToIgrac': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.service.DrzavaService jwd.festival.support.IgracDTOToIgrac.drzavaService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaDrzavaService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.repository.DrzavaRepository jwd.festival.service.impl.JpaDrzavaService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'drzavaRepository': Cannot create inner bean '(inner bean)#42b64ab8' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#42b64ab8': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utakmicaDTOToUtakmica': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.service.UtakmicaService jwd.festival.support.UtakmicaDTOToUtakmica.utakmicaService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaUtakmicaService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jwd.festival.repository.UtakmicaRepository jwd.festival.service.impl.JpaUtakmicaService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'utakmicaRepository': Cannot create inner bean '(inner bean)#3f2ef586' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f2ef586': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?

*** grupaDTOToGrupa:

package jwd.festival.support;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import jwd.festival.model.Grupa;
import jwd.festival.service.GrupaService;
import jwd.festival.web.dto.GrupaDTO;
@Component
public class GrupaDTOToGrupa implements Converter<GrupaDTO, Grupa> {

@Autowired
private GrupaService grupaService;

@Override
public Grupa convert(GrupaDTO source) {
    Grupa grupa;

    if(source.getId() == null) {
        grupa = new Grupa();
    }else {
        grupa = grupaService.findOne(source.getId());
        if(grupa == null) {
            throw new IllegalStateException("Triied to convert non existing 
object. GrupaDTOToGrupa");
        }
    }

    grupa.setId(source.getId());
    grupa.setNaziv(source.getNaziv());
    return grupa;
}

public List<Grupa> convert(List<GrupaDTO> grupe) {
    List<Grupa> ret = new ArrayList<>();

    for(GrupaDTO g : grupe) {
        ret.add(convert(g));
    }

    return ret;
}

}

*** igracDTOToIgrac:

package jwd.festival.support;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import jwd.festival.model.Igrac;
import jwd.festival.service.DrzavaService;
import jwd.festival.service.IgracService;
import jwd.festival.web.dto.IgracDTO;
@Component
public class IgracDTOToIgrac implements Converter<IgracDTO, Igrac> {

@Autowired
private DrzavaService drzavaService;

@Autowired
private IgracService igracService;

@Override
public Igrac convert(IgracDTO source) {
    Igrac igrac;

    if(source.getId() == null) {
        igrac = new Igrac();
        igrac.setDrzava(drzavaService.findOne(source.getDrzavaId()));
    } else {
        igrac = igracService.findOne(source.getId());
    }

    igrac.setDrzava(source.getDrzavaId());
    igrac.setId(source.getId());
    igrac.setIme(source.getIme());
    igrac.setPrezime(source.getPrezime());

    return igrac;
}

public List<Igrac> convert(List<IgracDTO> igraci) {
    List<Igrac> ret = new ArrayList<>();

    for(IgracDTO i : igraci) {
        ret.add(convert(i));
    }

    return ret;
}



}

*** utakmicaDTOToUtakmica:

package jwd.festival.support;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import jwd.festival.model.Utakmica;
import jwd.festival.service.UtakmicaService;
import jwd.festival.web.dto.UtakmicaDTO;
@Component
public class UtakmicaDTOToUtakmica implements Converter<UtakmicaDTO, 
Utakmica> {

@Autowired
private UtakmicaService utakmicaService;

@Override
public Utakmica convert(UtakmicaDTO source) {
    Utakmica utakmica;

    if(source.getId() == null) {
        utakmica = new Utakmica();
    }else {
        utakmica = utakmicaService.findOne(source.getId());
        if(utakmica == null) {
            throw new IllegalStateException("Tried to modify non existant 
utakmica. UtakmicaDTOToUtakmica");
        }
    }

    utakmica.setId(source.getId());
    utakmica.setDrzavaDomacin(source.getDrzavaDomacin());
    utakmica.setDrzavaGost(source.getDrzavaGost());
    utakmica.setRezultat(source.getRezultat());

    return utakmica;
}

public List<Utakmica> convert(List<UtakmicaDTO> utakmice) {
    List<Utakmica> ret = new ArrayList<>();

    for(UtakmicaDTO u : utakmice) {
        ret.add(convert(u));
    }

    return ret;
}

}

0 个答案:

没有答案