Tag: 春季启动

无法使用Kotlin和@AutoConfigureMockMvc检测测试类的默认配置类

我正在给Kotlin一个漩涡,并将下面的测试转换成Java运行良好的Kotlin。 使用IntelliJ转换工具转换测试后,我试图运行它,但我得到这个错误: 22:32:19.476 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner – SpringJUnit4ClassRunner constructor called with [class com.test.app.web.DeveloperControllerTest] 22:32:19.486 [main] DEBUG org.springframework.test.context.BootstrapUtils – Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 22:32:19.494 [main] DEBUG org.springframework.test.context.BootstrapUtils – Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 22:32:19.517 [main] DEBUG org.springframework.test.context.BootstrapUtils – Instantiating TestContextBootstrapper for test class [com.test.app.web.DeveloperControllerTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 22:32:19.539 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper – Neither @ContextConfiguration […]

响应状态HTTP SpringBoot Kotlin Api

我从kotlin开始,如果任何人都可以帮助我,我已经有一个关于如何返回http状态的问题,当我的真正的,如果它返回200好,当它的任何其他方式,返回404 NotFound。 我试着按照下面的代码来做,但是在所有情况下,它只返回状态200 OK @DeleteMapping("{id}") fun delete(@PathVariable id: Long): ResponseEntity<Unit> { try { if (dogRepository.exists(id)) { dogRepository.delete(id) } return ResponseEntity.ok().build() } catch (e: Exception) { return ResponseEntity.notFound().build() } }

Spring不能处理返回通用内部Kotlin类的方法

我是Kotlin新手,所以也许我误解了一些东西,但这个班级: @Component open class SimpleStoreBuilder { open fun <T : Entity> build(tableName: String): Store<T>? { return Store() } inner class Store<T:Entity> } 引发此运行时异常 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storeBuilder' defined in file [xxx\StoreBuilder.class]: Initialization of bean failed; nested exception is java.lang.reflect.GenericSignatureFormatError: Signature Parse error: expected '<' or ';' but got . Remaining input: .Store<TT;>; […]

Kotlin – lateinit TestRestTemplate不能初始化集成测试

我使用kotlin开发了一个spring-boot应用程序 – 总体情况进展顺利。 (spring 1.5.6.RELEASE,kotlin 1.1.4-3) 无论如何,我在回顾一些示例代码之后添加了我的第一个控制器测试,并且遇到了这个恼人的错误: kotlin.UninitializedPropertyAccessException:lateinit属性restTemplate尚未初始化 kotlin.UninitializedPropertyAccessException:lateinit属性testRestTemplate尚未初始化 at com.thingy.controllers.ProductSetControllerTest.getTestRestTemplate(ProductSetControllerTest.kt:16) at com.thingy.controllers.ProductSetControllerTest.testGet(ProductSetControllerTest.kt:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198) at org.testng.TestNG.runSuitesLocally(TestNG.java:1123) at […]

Kotlin测试失败从命令行与ClassNotFoundException但从IntelliJ工作

我在这里有一个Kotlin Spring Boot项目。 它有一些测试,从IntelliJ运行得很好,但是当我从命令行运行,失败,出现以下错误。 BUILD FAILED in 1m 12s 7 actionable tasks: 7 executed asarkar:license-report-kotlin$ ./gradlew clean test > Task :compileKotlin Using kotlin incremental compilation > Task :compileTestKotlin Using kotlin incremental compilation > Task :test 2017-07-16 21:43:06.345 INFO 2956 — [ Thread-13] scaAnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@54fa5525: startup date [Sun Jul 16 21:42:04 PDT 2017]; root […]

Kotlin spring-boot @ConfigurationProperties

我正在尝试创建以下bean AmazonDynamoDBAsyncClientProvider 。 我有application.properties定义endpoint和tablePrefix ,我试图注入使用@ConfigurationProperties 以下是相同的代码片段。 当我运行我的春季启动应用程序不起作用。 我已经尝试使用一个普通的java类来做相同的ConfigurationProperties类,它不会设置这些属性,但是当涉及到AmazonDynamoDBAsyncClientProvider ,属性是空的。 我在这里错过了什么? @Component open class AmazonDynamoDBAsyncClientProvider @Autowired constructor(val dynamoDBConfiguration: DynamoDBConfig){ @Bean open fun getAmazonDBAsync() = AmazonDynamoDBAsyncClientBuilder.standard() .withEndpointConfiguration( AwsClientBuilder.EndpointConfiguration(dynamoDBConfiguration.endpoint, dynamoDBConfiguration.prefix)) .build() } 这里是我试图用配置自动装配的kotlin bean @Component @ConfigurationProperties(value = "dynamo") open class DynamoDBConfig(var endpoint: String="", var prefix: String="") 最后继承了常规的java bean,它使用ConfigurationProperties填充,但是当它获得Autowired时,我看到这些属性为空/ null @Component @ConfigurationProperties("dynamo") public class DynamoDBConfiguration { private String endpoint; […]

Spring注解不能在Kotlin中工作

任何有注释问题都不适用于Kotlin? @Column(unique=true, nullable = false) @Size(min = 1, max = 50) var name: String = "", @Size(max = 100) var description: String = "" 我可以保存到空字符串的数据库和独特的约束也不通过注释工作。 任何人有类似的问题呢? 好心提醒 :)

Kotlin&Spring Boot @ConfigurationProperties

如何使用Kotlin正确初始化Spring Boot中的 ConfigurationProperties? 目前我喜欢在下面的例子中: @ConfigurationProperties("app") class Config { var foo: String? = null } 但它看起来相当丑陋,实际上foo是不可变的,foo是不变的 , 应该在启动过程中初始化,将来不会改变 。

Kotlin和DynamoDBMapper SaveBehavior

是否可以在Kotlin中正确使用SaveBehavior.UPDATE的SaveBehavior.UPDATE? // All save operations will use the UPDATE behavior by default DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient, new DynamoDBMapperConfig(SaveBehavior.UPDATE)); 该文件指出: 更新(默认) UPDATE不会影响保存操作中的未建模属性 ,而已建模属性的空值将从DynamoDB中的该项中删除它。 但是,在Kotlin中,您无法定义未建模的属性(您必须将它们分配给null或值)。 因此,没有设置的任何属性将实际清除数据库中的字段(null将清除),或将其分配给您的默认值。 我可以使用SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES但他们失去了清除数据库中的字段的能力。 参考: https : //aws.amazon.com/blogs/developer/using-the-savebehavior-configuration-for-the-dynamodbmapper/

与日食弹簧kotlin

我已经试过春季启动springtest,Kotlin日食简单的网络。 对于Java类,它可以进行热部署。 但不适用于Kotlin文件。 pom.xml几乎完全来自http://start.spring.io/,除了添加springloaded。 <build> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> </dependencies> </plugin> </plugins> </build>