Tag: 春季启动

使用Kotlin中的动态字段解析json对象

我有一个JSON对象: { “mobileNum”: “05x-xxxxxxx”, “appId”: “some_app”, “messageId”: “printUsersFirstTime”, “shouldSendDate”: “2017-10-03T16:20+03:00”, // this is optional “paramMap”: { “userName”: “some_name” }, “filters”: { “UNIQUE”: false, “RECENT”: “{ \”unit\”: \”MINUTE\”, \”size\”: 5 }” } 我使用Spring Boot和Kotlin。 Spring引导自动将提到的JSON映射到下面的模型bean: data class SmsDto( var mobileNum: String? = null, val appId: String? = null, val messageId: String? = null, var paramMap: Map? […]

在Kotlin注释参数中使用一个java常量

在Spring Boot(使用Java)中,我通常将缓存名称放在静态最终字符串中,如下所示: public static final String MY_CACHE_NAME = “cache_name” @Cacheable(value = MY_CACHE_NAME) 但是,当我有这个缓存名称的Java类,我尝试在一个Kotlin缓存的方法中使用,Eclipse告诉我这不是一个“编译时常量”。 有没有办法解决这个问题? 日食之外,一切都很好…

我的春季启动(Kotlin)控制器不工作,返回字符串

我正在努力做Kotlin的春季启动项目。 但我的控制器不工作..我想要打开的HTML文件所以我准备在resoureces /模板upload.html文件 以下方法返回字符串:( 源代码在这里 @RestController @RequestMapping(“/api”) class RestApiController { val logger = LoggerFactory.getLogger(RestApiController::class.java!!) @Autowired lateinit var parsingservice : ParsingService @GetMapping(“/index”) fun index(response : HttpServletResponse): String { return “upload” } 索引方法是返回“上传”,我希望在资源包中打开upload.html页面。 我研究了当Cotroller spring-boot框架中的方法返回String resoureces /模板路径扫描所以我们可以只写htmlfiles名称没有.html 我在这个网站搜索这个问题,我发现java9jdk不支持春季启动所以我重新安装java8jdk并更改项目设置。 但是这并没有奏效。 这是我的maven设置。 jsonparser Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE true UTF-8 UTF-8 1.8 1.2.10 org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot […]

SpringBoot + Jackson + Kotlin数据类:字段注释被忽略

我用Kotlin和Java8时间使用Spring Boot。 不知何故,数据类字段上的jackson注释被忽略。 import com.fasterxml.jackson.annotation.JsonProperty import java.time.MonthDay data class DataView(val id: String, @get:JsonProperty(“dayOfMonth”) val monthDay: MonthDay) {} 为什么这些注释会被忽略? 响应仍然包含字段名称“monthDay”。 我知道注释是正确的,根据这个讨论kotlinlang.org 。 就我所知,我没有任何应该影响这个的配置。 pom包含: … spring-boot-starter-parent org.springframework.boot 1.5.6.RELEASE … com.fasterxml.jackson.module jackson-module-kotlin ${jackson.version} com.fasterxml.jackson.datatype jackson-datatype-hibernate5 com.fasterxml.jackson.datatype jackson-datatype-hppc com.fasterxml.jackson.datatype jackson-datatype-jsr310 com.fasterxml.jackson.datatype jackson-datatype-json-org com.fasterxml.jackson.module jackson-module-afterburner …

Spring Boot 2.0.0.M7,Kotlin,Gradle-bean无法find

我试图运行一个在Kotlin中编写并使用Gradle构建的Spring Boot应用程序。 当我在IntelliJ中运行应用程序时,我收到以下消息: 应用程序启动失败 描述: com.mycompany.app.rest.api.MyApi中构造函数的参数1需要一个无法find的“com.mycompany.app.domain.UserRepository”types的bean。 行动: 考虑在你的配置中定义一个types为“com.mycompany.app.domain.UserRepository”的bean。 MYAPP: MyAPP目录结构和文件 Myapp.kt package com.mycompany.app.startbootapp import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = arrayOf(“com.mycompany.app”)) class MyApp fun main(args: Array) { runApplication(*args) } MyApi.kt package com.mycompany.app.rest.api import com.mycompany.app.domain.User import com.mycompany.app.domain.UserRepository import com.mycompany.app.infra.ParamUtil import com.mycompany.app.rest.api.inout.DtoUser import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController import javax.servlet.http.HttpServletRequest import […]

IntelliJ Idea 2017.3无法启动Kotlin Spring Boot App – @Configuration类可能不是最终的

我能够从IntelliJ 2017.3推出一个春季启动Kotlin应用程序。 在最后一次IntelliJ修复更新后,我无法从IDE启动该应用程序,得到此exception: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class ‘AccessConfig’ may not be final 我可以像往常一样从终端启动它: java -jar xxxx.jar 这是没有任何意义的,因为我在我的Gradle配置中使用必要的Kotlin Spring插件: buildscript { ext { kotlinVersion = ‘1.2.21’ springBootVersion = ‘2.0.0.RC1’ } repositories { mavenCentral() maven { url “https://repo.spring.io/snapshot” } maven { url “https://repo.spring.io/milestone” } jcenter() maven { url “https://plugins.gradle.org/m2/” } } dependencies { classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”) classpath(“org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}”) classpath(“org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}”) […]

使用命令行参数的Kotlin Gradle Spring bootRun任务

我有一个像下面的命令行亚军Kotlin春季启动应用程序。 @SpringBootApplication class MySpringApplication : CommandLineRunner { override fun run(vararg args: String?) { println(args[0]) } } fun main(args: Array) { val app = SpringApplication(MySpringApplication::class.java) app.setBannerMode(Banner.Mode.OFF) app.run(*args) } 我想知道如何通过命令行参数,当我使用gradle命令,./ ./gradlew bootRun ?

Spring引导validation注释不适用于Kotlin

我为Kotlin获得了一个简单的数据类 data class Person(val name: String, @get: Min(18) val age: Int) 我实际上是从CSV文件构建这个类,并使用apache CSV解析器读取CSV。 即使我有一些age小于18的数据,测试仍然没有通过任何错误。 看起来这个注释不适用于Kotlin?

在Spring Boot项目中使用Gradle从Kotlin测试引用Java代码时未解决的参考

我有一个项目,我正在使用Kotlin和Java代码。 我的主要Kotlin代码(包括@SpringBootApplication主类)在src / main / kotlin中,但是在src / main / java中有一些旧的客户端库代码。 我也在src / test / kotlin有一些测试。 在IntelliJ中,我可以运行测试没有问题,但是当我使用gradle测试运行测试时,我得到错误cannot access class ** Unresolved reference , cannot access class ** 。 我不确定这是为什么发生。 这些错误与Java类中的代码有关。 我的kotlin代码和测试与客户端库代码稍有不同, 我的主要代码位于名为com.sky.vision.playlistapi的包中,客户端库位于名为com.sky.nifty的包中。 我想知道这可能是问题的根源吗? 我的build.gradle文件在这里: buildscript { ext { kotlinVersion = ‘1.2.10’ } } plugins { id ‘java’ id ‘org.springframework.boot’ version ‘1.5.9.RELEASE’ id ‘org.jetbrains.kotlin.jvm’ version’1.2.10′ id ‘org.jetbrains.kotlin.plugin.allopen’ […]

Spring Boot 2&Kotlin 1.2.1:过时的运行时间

问题 我试图运行最新的kotlin版本(1.2.10),也是最新的spring boot(2.0.0.M7)。 在当地的环境一切都很好,但是–boottime intellij哭泣: 我已经看到过时的Kotlin运行时间 ,但在我看来,这是不连接所以…这是可疑的,因为我的以下build.gradle,只有一个版本的kotlin(只有一个)[前端也是gradle build,但node.js one – angular,no kotlin deps]: buildscript { ext { kotlinVersion = ‘1.2.10’ springBootVersion = ‘2.0.0.M7’ } repositories { mavenCentral() maven { url “https://repo.spring.io/snapshot” } maven { url “https://repo.spring.io/milestone” } maven { url “http://repo.spring.io/libs-milestone-local” } } dependencies { classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”) classpath(“org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}”) classpath(“org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}”) classpath ‘org.springframework:springloaded:1.2.6.RELEASE’ } } apply plugin: ‘kotlin’ […]