Olá!
Estou fazendo o curso "Agilidade e TDD: um dia no desenvolvimento de software", na segunda vídeo aula da seção "Implementando uma feature".
Baixei o projeto e apenas adicionei os códigos indicados nas aulas, mas quando tento subir a aplicação, me retornam as exceções:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'aircraftModelController' defined in file [C:\Users\maite.refosco\Desktop\Alura - Java\clines\target\classes\br\com\caelum\clines\api\aircraftmodels\AircraftModelController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'aircraftModelService' defined in file [C:\Users\maite.refosco\Desktop\Alura - Java\clines\target\classes\br\com\caelum\clines\api\aircraftmodels\AircraftModelService.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'aircraftModelRepository' defined in br.com.caelum.clines.api.aircraftmodels.AircraftModelRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class br.com.caelum.clines.shared.domain.AircraftModel
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aircraftModelRepository' defined in br.com.caelum.clines.api.aircraftmodels.AircraftModelRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class br.com.caelum.clines.shared.domain.AircraftModel
Caused by: java.lang.IllegalArgumentException: Not a managed type: class br.com.caelum.clines.shared.domain.AircraftModel
Classes que os erros se referem:
AircraftModelController:
package br.com.caelum.clines.api.aircraftmodels;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
import java.util.List;
import static org.springframework.http.ResponseEntity.created;
@RestController
@RequestMapping("aircraft-model")
@AllArgsConstructor
public class AircraftModelController {
private final AircraftModelService service;
@PostMapping
ResponseEntity<?> createBy(@RequestBody @Valid AircraftModelForm form) {
var id = service.createAircraftModelBy(form);
var uri = URI.create("/aircraft-model/").resolve(String.valueOf(id));
return created(uri).build();
}
@GetMapping
List<AircraftModelView> list() {
return service.listAllAircraftModels();
}
@GetMapping("{id}")
AircraftModelView show(@PathVariable Long id) {
return service.showAircraftModelBy(id);
}
}
AircraftModelService:
package br.com.caelum.clines.api.aircraftmodels;
import br.com.caelum.clines.shared.exceptions.ResourceAlreadyExistsException;
import br.com.caelum.clines.shared.exceptions.ResourceNotFoundException;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import static java.util.stream.Collectors.toList;
@Service
@AllArgsConstructor
public class AircraftModelService {
private final AircraftModelRepository repository;
private final AircraftModelFormMapper formMapper;
private final AircraftModelViewMapper viewMapper;
public Long createAircraftModelBy(AircraftModelForm form) {
repository.findByDescription(form.getDescription()).ifPresent(
(existingAircraftModel) -> {
throw new ResourceAlreadyExistsException("Aircraft Model already exists");
});
var aircraftModel = formMapper.map(form);
repository.save(aircraftModel);
return aircraftModel.getId();
}
public List<AircraftModelView> listAllAircraftModels() {
return repository.findAll().stream().map(viewMapper::map).collect(toList());
}
public AircraftModelView showAircraftModelBy(Long aircraftModelId) {
var aircraftModel = repository.findById(aircraftModelId).orElseThrow(() -> new ResourceNotFoundException("Cannot find aircraft model"));
return viewMapper.map(aircraftModel);
}
}