Spring не может обработать метод, возвращающий общий внутренний класс Kotlin

#spring #spring-boot #kotlin

#spring #spring-boot #kotlin

Вопрос:

Я новичок в Kotlin, поэтому, возможно, я что-то неправильно понял, но этот класс:

     @Component
    open class SimpleStoreBuilder {
           open fun <T : Entity> build(tableName: String): Store<T>? {
            return Store()
        }

        inner class Store<T:Entity>
    }
  

выдает это исключение во время выполнения

     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storeBuilder' defined in file [xxxStoreBuilder.class]: Initialization of bean failed; nested exception is java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected '<' or ';' but got .
        Remaining input: .Store<TT;>;
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
        at cz.webexo.ApplicationKt.main(Application.kt:28) [main/:na]
    Caused by: java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected '<' or ';' but got .
        Remaining input: .Store<TT;>;
        at sun.reflect.generics.parser.SignatureParser.error(SignatureParser.java:124) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parsePackageNameAndSimpleClassTypeSignature(SignatureParser.java:348) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseClassTypeSignature(SignatureParser.java:310) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:289) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseFieldTypeSignature(SignatureParser.java:283) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseTypeSignature(SignatureParser.java:485) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseReturnType(SignatureParser.java:627) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseMethodTypeSignature(SignatureParser.java:577) ~[na:1.8.0_101]
        at sun.reflect.generics.parser.SignatureParser.parseMethodSig(SignatureParser.java:171) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.ConstructorRepository.parse(ConstructorRepository.java:55) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.ConstructorRepository.parse(ConstructorRepository.java:43) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.AbstractRepository.<init>(AbstractRepository.java:74) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.GenericDeclRepository.<init>(GenericDeclRepository.java:49) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.ConstructorRepository.<init>(ConstructorRepository.java:51) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.MethodRepository.<init>(MethodRepository.java:46) ~[na:1.8.0_101]
        at sun.reflect.generics.repository.MethodRepository.make(MethodRepository.java:59) ~[na:1.8.0_101]
        at java.lang.reflect.Method.getGenericInfo(Method.java:102) ~[na:1.8.0_101]
        at java.lang.reflect.Method.getGenericInfo(Method.java:61) ~[na:1.8.0_101]
        at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:283) ~[na:1.8.0_101]
        at java.lang.reflect.Method.getGenericParameterTypes(Method.java:283) ~[na:1.8.0_101]
        at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387) ~[na:1.8.0_101]
        at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116) ~[na:1.8.0_101]
        at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72) ~[na:1.8.0_101]
        at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56) ~[na:1.8.0_101]
        at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1205) ~[na:1.8.0_101]
        at java.beans.Introspector.getBeanInfo(Introspector.java:426) ~[na:1.8.0_101]
        at java.beans.Introspector.getBeanInfo(Introspector.java:262) ~[na:1.8.0_101]
        at java.beans.Introspector.getBeanInfo(Introspector.java:204) ~[na:1.8.0_101]
        at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:278) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:189) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:173) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:248) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1373) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
        ... 15 common frames omitted
  

Это ошибка или я делаю что-то не так?

Спасибо

Ответ №1:

Мне жаль это говорить, но это известная ошибка: https://youtrack.jetbrains.com/issue/KT-10397

Я думаю, что на данный момент будет лучше создать конкретный класс на основе общего и использовать его в качестве возвращаемого типа.