Tag: 弹簧

为什么Kotlin类不需要在Spring Boot中打开了

在关于Kotlin和Spring Boot的最新video: Spring Tips:Bootiful Kotlin Redux 。 Spring Boot的Application类看起来像: class SpringBootKotlinApplication fun main(args: Array) { } 我记得Kotlin必须注明在Spring Boot中是open 。 open class SpringBootKotlinApplication 看这个video 。 那么为什么现在没有必要注释? Spring Boot是否需要现在扩展Application类?

用Kotlin建立一个Spring Boot项目

我开始了一个学习Kotlin的新项目,我在Spring Initializr中获得了一个项目模板,并创建了一个控制器来映射我的资源。 StudentController @RestController class StudentController { @GetMapping(“/students”) fun getStudent(): Student { return Student(“name”, “test”) } } 应用 @SpringBootApplication class DemoApplication fun main(args: Array) { SpringApplication.run(DemoApplication::class.java, *args) } application.properties debug=true 我运行项目,当我发送GET请求到本地主机:8080 /学生,我收到了404。 { “timestamp”: 1501961340149, “status”: 404, “error”: “Not Found”, “message”: “No message available”, “path”: “/students” } 我做错了什么?

@CreationTimestamp和@UpdateTimestamp在Kotlin中不起作用

这是我的标记和发布实体类: @Entity class Tag( @get:NotBlank @Column(unique = true) val name: String = “”, val description: String = “” ) { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) val id: Int? = null @ManyToMany(mappedBy = “tags”) val posts: MutableSet = mutableSetOf() @CreationTimestamp lateinit var createDate: Date @UpdateTimestamp lateinit var updateDate: Date fun addPost(post: Post) { this.posts.add(post) post.tags.add(this) } } […]

使用Kotlin BeanDefinitionDsl时不会调用@PostConstruct

当使用Kotlin BeanDefinitionDsl将bean添加到上下文中时,似乎不会调用@PostConstruct方法。 这发生在我自己的项目中,但创建一个简单的方法来重现它,这就是我所做的。 我分叉使用Kotlin DSL的Spring示例https://github.com/sdeleuze/spring-kotlin-functional 我添加了@PostConstruct到UserHandler类。 (更多细节在下面) 我把结果推到这里: https : //github.com/benjishults/spring-kotlin-functional 所以你所要做的就是分叉我的回购,并做一个gradle运行。 我的问题是: 我不应该期望@PostConstruct被调用,因为我把这个类作为一个bean来使用吗? 我错过了一个步骤? 这是一个spring的bug? 如果你不想拉我的回购,这里是更多的细节,我做了什么。 我将其添加到UserHandler类: @PostConstruct fun afterPropertiesSet() { System.out.println(“AFTER PROPERTIES SET CALLED”) } 以及导入和Gradle依赖。 UserHandler bean被拉入到上下文中,使用一个调用bean beans的bean方法,如下所示: fun beans() = beans { bean() // … } 这是带来的上下文: beans().initialize(context)