2017-02-13 5 views
1

Я получаю эту ошибку:Ошибка создания боба с именем «fieldServiceImpl» определен в файле []: Неудовлетворенная зависимость выражается через параметр конструктора 1

2017-02-13 11:53:48.497 WARN 13276 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldServiceImpl' defined in file [...\bin\co\com\service\impl\FieldServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'co.com.service.mapper.FieldMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

2017-02-13 11:53:48.679 WARN 13276 --- [ restartedMain] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)

*************************** APPLICATION FAILED TO START


Description:

Parameter 1 of constructor in co.com.service.impl.FieldServiceImpl required a bean of type 'co.com.service.mapper.FieldMapper' that could not be found.

Action:

Consider defining a bean of type 'co.com.service.mapper.FieldMapper' in your configuration.

У меня есть эти классы: FieldMapper.java

package co.com.service.mapper; 

import co.com.domain.*; 
import co.com.service.dto.FieldDTO; 

import org.mapstruct.*; 
import java.util.List; 

/** 
* Mapper for the entity Field and its DTO FieldDTO. 
*/ 
@Mapper(componentModel = "spring", uses = {}) 
public interface FieldMapper { 

    FieldDTO fieldToFieldDTO(Field field); 

    List<FieldDTO> fieldsToFieldDTOs(List<Field> fields); 

    @Mapping(target = "productionOrderFields", ignore = true) 
    Field fieldDTOToField(FieldDTO fieldDTO); 

    List<Field> fieldDTOsToFields(List<FieldDTO> fieldDTOs); 
} 

FieldService.java

package co.com.service; 

import co.com.service.dto.FieldDTO; 
import java.util.List; 

/** 
* Service Interface for managing Field. 
*/ 
public interface FieldService { 

    /** 
    * Save a field. 
    * 
    * @param fieldDTO the entity to save 
    * @return the persisted entity 
    */ 
    FieldDTO save(FieldDTO fieldDTO); 

    /** 
    * Get all the fields. 
    * 
    * @return the list of entities 
    */ 
    List<FieldDTO> findAll(); 

    /** 
    * Get the "id" field. 
    * 
    * @param id the id of the entity 
    * @return the entity 
    */ 
    FieldDTO findOne(Long id); 

    /** 
    * Delete the "id" field. 
    * 
    * @param id the id of the entity 
    */ 
    void delete(Long id); 
} 

FieldServiceImp l.java

package co.com.service.impl; 

import co.com.service.FieldService; 
import co.com.domain.Field; 
import co.com.repository.FieldRepository; 
import co.com.service.dto.FieldDTO; 
import co.com.service.mapper.FieldMapper; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.transaction.annotation.Transactional; 
import org.springframework.stereotype.Service; 

import java.util.LinkedList; 
import java.util.List; 
import java.util.stream.Collectors; 

/** 
* Service Implementation for managing Field. 
*/ 
@Service 
@Transactional 
public class FieldServiceImpl implements FieldService{ 

    private final Logger log = LoggerFactory.getLogger(FieldServiceImpl.class); 

    private final FieldRepository fieldRepository; 

    private final FieldMapper fieldMapper; 

    public FieldServiceImpl(FieldRepository fieldRepository, FieldMapper fieldMapper) { 
     this.fieldRepository = fieldRepository; 
     this.fieldMapper = fieldMapper; 
    } 

    /** 
    * Save a field. 
    * 
    * @param fieldDTO the entity to save 
    * @return the persisted entity 
    */ 
    @Override 
    public FieldDTO save(FieldDTO fieldDTO) { 
     log.debug("Request to save Field : {}", fieldDTO); 
     Field field = fieldMapper.fieldDTOToField(fieldDTO); 
     field = fieldRepository.save(field); 
     FieldDTO result = fieldMapper.fieldToFieldDTO(field); 
     return result; 
    } 

    /** 
    * Get all the fields. 
    * 
    * @return the list of entities 
    */ 
    @Override 
    @Transactional(readOnly = true) 
    public List<FieldDTO> findAll() { 
     log.debug("Request to get all Fields"); 
     List<FieldDTO> result = fieldRepository.findAll().stream() 
      .map(fieldMapper::fieldToFieldDTO) 
      .collect(Collectors.toCollection(LinkedList::new)); 

     return result; 
    } 

    /** 
    * Get one field by id. 
    * 
    * @param id the id of the entity 
    * @return the entity 
    */ 
    @Override 
    @Transactional(readOnly = true) 
    public FieldDTO findOne(Long id) { 
     log.debug("Request to get Field : {}", id); 
     Field field = fieldRepository.findOne(id); 
     FieldDTO fieldDTO = fieldMapper.fieldToFieldDTO(field); 
     return fieldDTO; 
    } 

    /** 
    * Delete the field by id. 
    * 
    * @param id the id of the entity 
    */ 
    @Override 
    public void delete(Long id) { 
     log.debug("Request to delete Field : {}", id); 
     fieldRepository.delete(id); 
    } 
} 

Что мне делать? Заранее спасибо

ответ

0

Как вы определили один 2-аргумент consturctor в классе, вы должны autowire зависимостей, так что весна знает, что вводить и как вызвать конструктор:

@Autowired 
public FieldServiceImpl(FieldRepository fieldRepository, FieldMapper fieldMapper) { 
     this.fieldRepository = fieldRepository; 
     this.fieldMapper = fieldMapper; 
} 

В качестве альтернативы положить autowired на полях и удалить consturctor вообще:

@Autowired 
private FieldRepository fieldRepository; 

@Autowired 
private FieldMapper fieldMapper; 

Upate

Кроме того, я думаю, вам нужно иметь где-то реализацию интерфейса FieldMapper, и он должен быть отмечен @Component или @Service аннотации:

@Component 
public class FieldMapperImpl implements FieldMapper{} 

Как мне кажется, что реализация не зарегистрирована в весеннем Cotnext.

 Смежные вопросы

  • Нет связанных вопросов^_^