Tag: spring起动

在@Transactional方法调用期间,初始化期间Bean属性不为null变为null

我遇到了一个问题,在调用@Transactional方法期间bean的属性变为null。 UserService是在@Configuration类中声明的一个bean userRepository和passwordService在初始化期间是非空的(afterPropertiesSet) 在调用registerUser( @Transactional )期间,这些属性将变为null 这些属性具有不可空的types 用户服务的相同实例/ bean已根据打印使用 删除@Transactional似乎解决了这个问题 添加或删除@EnableTransactionManagement似乎什么都不做 服务: open class UserService (val userRepository: UserRepository, val passwordService: PasswordService) : InitializingBean { override fun afterPropertiesSet() { println(“### this.afterPropertiesSet”) println(“### this: ” + this) println(“### userRepository: ” + userRepository) println(“### passwordService: ” + passwordService) } @Transactional fun registerUser(request: UserRegistrationRequest): User { println(“### this.registerUser”) println(“### […]

Spring Boot将文本/ JavaScript序列化为JSON

我创建了以下Kotlin数据类: @JsonInclude(JsonInclude.Include.NON_NULL) public data class ITunesArtist(val artistName: String, val artistId: Long, val artistLinkUrl: URL) (一个数据类是一个Kotlin类,可以在编译时自动生成equals,hashcode,toString等 – 节省时间)。 现在我试着使用Spring RestTemplate填充它: @Test fun loadArtist() { val restTemplate = RestTemplate() val artist = restTemplate.getForObject( “https://itunes.apple.com/search?term=howlin+wolf&entity=allArtist&limit=1”, ITunesQueryResults::class.java); println(“Got artist: $artist”) } 它失败: Could not extract response: no suitable HttpMessageConverter found for response type [class vampr.api.service.authorization.facebook.ITunesArtist] and content type [text/javascript;charset=utf-8] […]

无法find参数的方法springBoot() – 使用Kotlin的Spring Boot

我尝试用Kotlin创建第一个Spring Boot应用程序。 所以,也许我做了一些明显的错误或类似的东西。 我的gradle.build是: buildscript { ext.kotlin_version = ‘1.0.5-2’ ext.spring_boot_version = ‘1.4.2.RELEASE’ repositories { jcenter() } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” classpath “org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version” } } apply plugin: ‘idea’ apply plugin: ‘kotlin’ apply plugin: ‘application’ jar { baseName = ‘rest-voter’ version = ‘0.1.0’ } springBoot { mainClass = ‘ru.hixon.Application’ } repositories { jcenter() } dependencies { compile […]

Spring Boot + Kotlin AutoProxyRegistrar导致Nullpointerexception

Hej大家,我正在尝试从java 8迁移一个小的spring引导项目到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 […]