kotlin (Spring boot 2 + JPA + mysql) - Error creating bean with name

0

I'm working with

  • kotlinVersion = '1.2.51'
  • springBootVersion = '2.0.5.RELEASE'
  • java 8

but I have an error when compiling the code I get something like

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgisCatMunicipiosController' defined in file [C:\Users\Sistemas\IdeaProjects\tks\out\production\classes\com\tksys\tks\controller\DgisCatMunicipiosController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgisCatMunicipiosServiceImpl' defined in file [C:\Users\Sistemas\IdeaProjects\tks\out\production\classes\com\tksys\tks\services\impl\DgisCatMunicipiosServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dgisCatMunicipiosRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.tksys.tks.repository.DgisCatMunicipiosRepository.findAllByCve_entidad(int)! No property cve found for type DgisCatMunicipios!
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]

I have a code almost exactly like the one that gives me an error but that does work.

Controller

@RestController
@RequestMapping("/dgis_cat_municipios")
class DgisCatMunicipiosController(@Autowired val dgis_cat_municipiosService: Dgis_cat_municipiosService) {
    @RequestMapping(value = ["/search-by-cve-entidad"],
            method = [RequestMethod.GET],
            produces = [MediaType.APPLICATION_JSON_VALUE])
    fun searchByCve_entidad(@RequestParam("cve_entidad") cve_entidad : Int):List<DgisCatMunicipios>{
        return dgis_cat_municipiosService.searchByCve_entidad(cve_entidad)
    }
}

Model

@Entity
@Table(name = "dgis_cat_municipios")
data class DgisCatMunicipios(@Id @Column(name = "cve_municipio") var cve_municipio: Int? = 0,
                             @Column(name = "cve_entidad") var cve_entidad: Int? = 0,
                             @Column(name = "nom_municipio") var nom_municipio: String? = null,
                             @Column(name = "estatus") var estatus: String? = null
)

Repository

@Repository
interface DgisCatMunicipiosRepository : JpaRepository<DgisCatMunicipios, Int> {
    fun findAllByCve_entidad(cve_entidad: Int): List<DgisCatMunicipios>
}

Service

interface Dgis_cat_municipiosService {
    fun searchByCve_entidad(cve_entidad: Int): List <DgisCatMunicipios>
}

ServiceImpl

@Service
data class DgisCatMunicipiosServiceImpl(@Autowired val dgis_cat_municipiosRepository: DgisCatMunicipiosRepository) : Dgis_cat_municipiosService {
    override fun searchByCve_entidad(cve_entidad: Int): List<DgisCatMunicipios> {
        return dgis_cat_municipiosRepository.findAllByCve_entidad(cve_entidad)
    }
}

I enclose the 2 codes one that I tell you that if it works without problems ( User ) and the one I put right now that gives me that error ( tks ) ...

I hope you can help me because I do not understand why it is the error and I already have a couple of days like this ..

Thanks in advance to everyone ...

    
asked by Hugo Nieves Meza 24.09.2018 в 22:59
source

0 answers