我想修改我的应用程序的工作方式,取决于–debug开关是否存在。 我在@Configuration文件中试过这个: @Value("\${debug}") lateinit var debug: String 但春天说 无法在值“$ {debug}”中解析占位符“调试” 我如何查询–debug选项的状态?
我创建了以下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] […]
我遇到了一个问题,在调用@Transactional方法期间bean的属性变为null。 UserService是在@Configuration类中声明的一个bean userRepository和passwordService在初始化期间是非空的(afterPropertiesSet) 在调用registerUser( @Transactional )期间,这些属性将变为null 这些属性具有不可空的类型 用户服务的相同实例/ 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中更改属性占位符的前缀和后缀最简单的方法是什么? 默认值是@Value("${some.property}") ,但是这在Kotlin中看起来很丑,因为它需要被转义 – $ {something}是Kotlin中String模板的语言特性。