大家好, 我正在尝试将一个小的spring boot项目从java 8迁移到kotlin。 我遇到了一个问题,我有以下配置类
@EnableCaching
@Configuration
open class CacheConfiguration : CachingConfigurer {
@Bean
override fun cacheManager(): CacheManager {
return ConcurrentMapCacheManager()
}
@Bean
override fun cacheResolver(): CacheResolver {
return SimpleCacheResolver(cacheManager())
}
/**
* Simple Key Generator
* @return not null
*/
@Bean
override fun keyGenerator(): KeyGenerator {
return SimpleKeyGenerator()
}
@Bean
override fun errorHandler(): CacheErrorHandler {
return SimpleCacheErrorHandler()
}
}
这是实际的课程。这是我的项目中第一个也是唯一一个kotlin类。 现在使用gradle bootRun启动项目会导致
中出现Nullpointer异常AutoProxyRegistrar.java#L63
AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
Object mode = candidate.get("mode"); <-- candidate is null
它尝试检索注释属性,这适用于我提供的2个注释
@EnableCaching
@Configuration
虽然看起来kotlin添加了一个名为kotlin.Metadata的新注释 看似无法处理。
buildscript {
ext {
ext.kotlin_version = '1.0.5-2'
springBootVersion = '1.4.3.RELEASE'
asciiDoctorVersion = '1.5.2'
snippetsDir = file('build/generated-snippets')
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.asciidoctor:asciidoctor-gradle-plugin:${asciiDoctorVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'kotlin'
apply plugin: 'org.asciidoctor.convert'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14'
}
test {
outputs.dir snippetsDir
testLogging {
events "passed", "skipped", "failed", "standardError"
}
}
task stage {
dependsOn build
}
asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
dependsOn test
}
// Force ./gradlew cleanTest
allprojects {
tasks.matching { task -> task.name == "test" }.all {
outputs.upToDateWhen { false }
}
}
dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-actuator')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-security')
compile(group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.0.10.RELEASE')
compile(group: 'org.springframework.security', name: 'spring-security-jwt', version: '1.0.4.RELEASE')
compile(group: 'org.postgresql', name: 'postgresql', version: '9.4.1209.jre7')
testCompile(group: 'com.jayway.restassured', name: 'rest-assured', version: '2.9.0')
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test')
}
我创建了一个小型存储库来重现此问题。 https://github.com/spring-projects/spring-framework-issues/pull/145 这个https://jira.spring.io/browse/SPR-15055