Tag: 弹簧

来自YML的ConfigurationProperties加载列表

我试图从YML加载配置。 我可以加载值,我也可以加载列表,如果这些是逗号分隔值。 但是我不能加载一个典型的YML列表。 配置类 @Component @PropertySource("classpath:routing.yml") @ConfigurationProperties class RoutingProperties(){ var angular = listOf("nothing") var value: String = "" } 工作routing.yml angular: /init, /home value: Hello World 不工作routing.yml angular: – init – home value: Hello World 为什么我不能加载第二版的yml /我有一个syntaxt错误? ENV:Kotlin,Spring 2.0.0.M3

Spring REST,Kotin和默认的基本参数导致错误

我得到一个错误: 可选的长参数“count”存在,但由于被声明为基本类型而不能被转换为空值。 考虑将其声明为相应原始类型的对象包装 当我尝试调用这个REST控制器。 @RequestMapping("/api/audio/tracks", produces = arrayOf(APPLICATION_JSON_VALUE)) interface SomeApi { @RequestMapping(method = arrayOf(GET)) fun list(@RequestParam("count", defaultValue = "10") count: Long): Any } 不会春天看defaultValue吗? 如何解决这类问题? !Kotlin默认也不起作用

我可以写一个使用自动布线的Spring bean的Kotlin扩展函数吗?

我试图创建一个扩展函数,其实现使用Spring bean。 通过在包的顶层定义扩展功能,似乎不可能做到这一点。 我试过这个: @Component class Converter { companion object { @Autowired lateinit var transformer: Transformer fun Class1.convert(): Class2 { return Class2 (this, transformer.transform(someStringProperty)) } } } 其中transform是将某个字符串转换为另一个字符串的函数,而Class1则是一些具有someStringProperty属性的类。 我希望其他类可以import pkg.Converter.Companion.convert ,然后可以使用x.convert() ,其中x是Class1类型的对象。 语法工作,并在其他类中使用x.convert()编译罚款。 但在运行时会导致异常: kotlin.UninitializedPropertyAccessException: lateinit property transformer has not been initialized 它看起来像Spring不是自动装配的变量,因为它在一个伴侣对象,而不是一个实际的组件对象。 使用@Component注释伴随对象不起作用。 我不认为直接在Converter内移动Class1.convert会工作,因为然后使用x.convert()将需要一个Converter对象的实例,我不明白如何使用扩展函数语法来做到这一点。 有没有办法做到这一点,或者我不得不放弃扩展函数语法?

Kotlin无法在类中使用@Configuration @EnableWebMvc注释创建@Autowired字段

初始化项目时,自动Autowired字段为null : package com.lynas.config import org.springframework.stereotype.Component import org.springframework.web.servlet.handler.HandlerInterceptorAdapter import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse @Component open class InterceptorConfig : HandlerInterceptorAdapter() { override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any?): Boolean { return true } } package com.lynas.config import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.EnableWebMvc import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Configuration @EnableWebMvc @ComponentScan("com.lynas") open class WebConfig() : WebMvcConfigurerAdapter() […]

找到未索引的远程资源库

我将Spring框架源代码导入到InteliJ IDEA 2016.3,只想读取一些源代码。 但在处理中,它表明 “未索引的远程Maven仓库发现”禁用… dl.bintray.com/kotlin/kotlin-eap-1.1 repo.spring.io/libs-snapshot repo.spring.io/plugins-snapshot repo.spring.io/milestone 我“更新”“repo.spring.io/libs-snapshot”存储库,index.gz是200M +。 我想知道,如果我离开它。 只是禁用通知。 会造成任何问题吗?

使用Kotlin功能DSL编写导航配置

我喜欢Spring java-config的一件事是能够按照这样的模式使我的配置非常可浏览。 这使我可以拆分我的配置并轻松地导航配置。 我一直在尝试使用BeanDefinitionDsl来做这样的事情,这比我所期望的更麻烦。 你们中的任何一个人是否有可能将@Import的等价物拉入BeanDefinitionDsl? 我已经尝试了很多东西,但都没有碰到任何东西,这两个工程,很好的导航。

Spring Web Flux(反应式)功能路由与Kotlin无法正常工作

你好有兴趣在Kotlin编写Spring应用程序的人。 我正在玩Spring Boot 2.0.0快照和spring-webflux 。 这段代码: @Component class TestRouter() : RouterFunction<ServerResponse> { override fun route(request: ServerRequest) = route(request) { "/".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World")) } "/{id}".route { GET("/hello") { ServerResponse.ok().body(BodyInserters.fromObject("World ${request.pathVariable("id")}")) } } } } } 不按预期工作(至少如我所料:)) ➜ ~ curl -i http://localhost:8080/hello HTTP/1.1 200 OK transfer-encoding: chunked Content-Type: text/plain;charset=UTF-8 World 但: ➜ ~ curl -i […]

如何在基本类型中使用kotlin中的@Autowired或@Value等Spring注解?

使用类似Spring的注释自动装配非基元 @Autowired lateinit var metaDataService: MetaDataService 作品。 但是这不起作用: @Value("\${cacheTimeSeconds}") lateinit var cacheTimeSeconds: Int 有一个错误: 基元类型不允许使用lateinit修饰符。 如何autotire primitve属性到kotlin类?

Kotlin数据类上的Spring构造函数注解,具有默认值

要使用弹簧持久性,但保持不可变类型,我已经将PersistenceConstructor注释添加到我的数据类中。 这告诉spring在从数据库加载类时使用该构造函数。 但是,我很难找到构造函数的春天。 data class MyData @PersistenceConstructor constructor(@Id val id: Int? = null, val a:String) 这在我的机器上100%的时间工作,但是当部署到heroku时,它始终失败。 看起来,通过具有参数默认值kotlin生成多个构造函数,但问题是,每个构造函数都得到应用于它们的注释,所以它只是运气(或特定的JDK实现),哪一个春天拿起。 默认的参数没有名字,所以Spring不知道如何处理它。 我真正的构造函数比这更大,所以没有默认值将是一个痛苦。 有没有办法让注释只适用于没有默认值的构造函数?

如何将IoC注入到Kotlin顶级函数中? 我甚至使用IoC容器?

我很难遵循FP。 当人们说“更习惯风格”时,我必须明白:99%的Java库不适用于Kotlin和Scala的FP惯用风格吗? 那么,我需要Spring Boot来快速启动Vaadin。 所以我需要注入一些豆子。 package com.x.ui import com.vaadin.icons.VaadinIcons import com.vaadin.navigator.Navigator import com.vaadin.ui.MenuBar fun createMenuBar(navigator: Navigator): MenuBar { val menuBar = MenuBar() menuBar.setHeight(null) menuBar.setWidth(null) menuBar.addItem("Dashboard", VaadinIcons.COG, { navigator.navigateTo("Dashboard") } as MenuBar.Command) return menuBar } 那么如何将SpringNavigator注入到这个函数中呢? 由于我已经有几个顶级功能,所以我没有@Component既没有@Bean,也没有使用Spring IoC for Kotlin的惯用方法? 我仅限于使用课程,或者我们有技巧做到这一点?