0
I’m having a mistake in Spring and I’m not getting a very good understanding of what’s going on, could you help me?
- LOG
09:25:43.038 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'listarVeiculosController': Unsatisfied dependency expressed through field 'veiculoRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'veiculoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class br.com.itau.ev9.fuse.model.VeiculoCotacao
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at br.com.itau.ev9.fuse.App.main(App.java:35)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'veiculoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class br.com.itau.ev9.fuse.model.VeiculoCotacao
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1128)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: Not an managed type: class br.com.itau.ev9.fuse.model.VeiculoCotacao
at org.hibernate.ejb.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:200)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:70)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:67)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:152)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:99)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:199)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 29 common frames omitted
- listVeiculosController
@Controller
public class ListarVeiculosController {
@Autowired
VeiculoRepository veiculoRepository;
public void request(Exchange exchange) {
try {
RetornoData data = new RetornoData();
List<BuscarVeiculosDTO> listaResponse = new ArrayList();
List<VeiculoCotacao> listaVeiculos = new ArrayList();
int anoModelo = Integer.parseInt(exchange.getProperty("year").toString());
String stringPesquisa = exchange.getProperty("search_terms").toString();
Boolean zeroKm = Boolean.parseBoolean(exchange.getProperty("zero_km").toString());
//listaVeiculos = (List<VeiculoCotacao>) veiculoRepository.findBySearchTerms(anoModelo, stringPesquisa);
listaVeiculos = (List<VeiculoCotacao>) veiculoRepository.findAll();
for (VeiculoCotacao veiculoCotacao : listaVeiculos) {
BuscarVeiculosDTO veiculo = new BuscarVeiculosDTO();
veiculo.setCodigoMolicar(veiculoCotacao.getCdMolicar());
veiculo.setMarca(veiculoCotacao.getMarca());
veiculo.setModelo(veiculoCotacao.getModelo());
listaResponse.add(veiculo);
}
data.setData(listaResponse);
exchange.getIn().setBody(data);
} catch (Exception e) {
exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, HttpStatus.INTERNAL_SERVER_ERROR);
exchange.setException(new VeiculoException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()));
}
}
}
- Veiculocotacao.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class VeiculoCotacao {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private int idICarros;
private int anoInicial;
private int anoFinal;
private String marca;
private String modelo;
private String cdMolicar;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public int getIdICarros() {
return idICarros;
}
public void setIdICarros(int idICarros) {
this.idICarros = idICarros;
}
public int getAnoInicial() {
return anoInicial;
}
public void setAnoInicial(int anoInicial) {
this.anoInicial = anoInicial;
}
public int getAnoFinal() {
return anoFinal;
}
public void setAnoFinal(int anoFinal) {
this.anoFinal = anoFinal;
}
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getModelo() {
return modelo;
}
public void setModelo(String modelo) {
this.modelo = modelo;
}
public String getCdMolicar() {
return cdMolicar;
}
public void setCdMolicar(String cdMolicar) {
this.cdMolicar = cdMolicar;
}
}
- Veiculorepository.java
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import br.com.itau.ev9.fuse.model.VeiculoCotacao;
@Repository
public interface VeiculoRepository extends CrudRepository<VeiculoCotacao, Integer>{
}
You can also put your configuration class?
– Bruno