spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
https://spring.io/projects/spring-data
Apache License 2.0
778 stars 675 forks source link

Consider Kotlin metadata annotation for Kotlin class kind retrieval [DATACMNS-1245] #1685

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 6 years ago

Juergen Zimmermann opened DATACMNS-1245 and commented

After upgrading from Kotlin 1.2.10 to 1.2.20 I'm getting the error log below. My own class DbConfig (because of TLS connection w/ MongoDB) is derived from org.springframework.data.mongodb.config.AbstractMongoConfiguration, and just inherits mappingMongoConverter() which invokes org.springframework.data.mongodb.config.MongoConfigurationSupport.mongoMappingContext(). I'll attach my own files DbConfig.kt and DbReactiveConfig.kt.

The error log:

2018-01-17 13:16:14.518 WARN 16544 --- [ restartedMain] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration$AnnotationConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.server.reactive.HttpHandler]: Factory method 'httpHandler' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration$EnableWebFluxConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfiguration': Unsatisfied dependency expressed through field 'reactiveUserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customUserDetailsService' defined in file [C:\Users\ziju0001\IdeaProjects\kunde\build\classes\kotlin\main\de\hska\kunde\config\security\CustomUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customUserDetailsRepository': Cannot resolve reference to bean 'reactiveMongoTemplate' while setting bean property 'reactiveMongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reactiveMongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveMongoTemplate' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [de/hska/kunde/config/DbReactiveConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [de/hska/kunde/config/DbConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/impl/load/kotlin/reflect/ReflectKotlinClass


Affects: 2.0.2 (Kay SR2)

Attachments:

Referenced from: pull request https://github.com/spring-projects/spring-data-commons/pull/269

Backported to: 2.0.3 (Kay SR3)

1 votes, 4 watchers

spring-projects-issues commented 6 years ago

Mark Paluch commented

We're using Kotlin internals to determine whether a particular class type is supported or not. In particular, we only support regular classes (no facades/SAM classes/multi-file classes). This check is required as unsupported classes cause exceptions within Kotlin libraries so we're basically guarding all code from Kotlin bugs.

Kotlin changed its internals and moved around packages

spring-projects-issues commented 6 years ago

Mark Paluch commented

Moved to Spring Data Commons and changed this ticket to a task adopting to Kotlin 1.2.20

spring-projects-issues commented 6 years ago

Mark Paluch commented

I pushed a change to the DATACMNS-1245 branch that picks up Kotlin's changes. Care to give 2.1.0.DATACMNS-1245-SNAPSHOT a spin?

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-commons</artifactId>
  <version>2.1.0.DATACMNS-1245-SNAPSHOT</version>
</dependency>

<repository>
  <id>spring-libs-snapshot</id>
  <name>Spring Snapshot Repository</name>
  <url>http://repo.spring.io/libs-snapshot</url>
</repository>
spring-projects-issues commented 6 years ago

Juergen Zimmermann commented

The issue is gone after I added org.springframework.data:spring-data-commons:2.1.0.DATACMNS-1245-SNAPSHOT in build.gradle

spring-projects-issues commented 6 years ago

Mark Paluch commented

Changed the pull request to evaluate Kotlin's @Metadata annotation after feedback from Jetbrains

spring-projects-issues commented 6 years ago

Juergen Zimmermann commented

@mp911de What is the implication after your PR is declined? Can I test something different?

spring-projects-issues commented 6 years ago

Mark Paluch commented

No worries, the PR isn't declined, the code is merged. GitHub expects the same commit hash in the target branch to consider a pull request merged. We use cherry-picking to bring our commits from a feature branch into master and service-release branches. That said, you can use 2.0.3 and 2.1.0 snapshots that already contain the fix