Tag: 春天

Gradle脚本Kotlin和dependencyManagement

我正尝试将Spring Cloud Stream应用程序构建脚本移植到Kotlin。 到目前为止,除了依赖关系管理块之外,这么好。 网上很难找到任何东西。 样本也不包括该主题。 如何将下面的块转换为build.gradle.kts ? 谢谢。 dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR2" } }

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 + Spring AliasFor

我一直在尝试在Kotlin项目中使用Springs @AliasFor注解,但注解参数上的注释看起来在运行时是不可见的(因此Spring没有采用它)。 例如: @RequestMapping(method = arrayOf(RequestMethod.POST)) annotation class PostMapping( @get:AliasFor(annotation = RequestMapping::class, attribute = "value") vararg val value: String = arrayOf()) 和… // Returns empty array instead of array with the @AliasFor annotation PostMapping::class.java.methods[0].annotations 有什么我失踪?

kotlin中的数字是不可序列化的

我发现kotlin中的数字是不可序列化的。 第一个问题 Device.kt: package test.domain import javax.persistence.* Entity public class Device { public Id GeneratedValue var id: Long = -1 public var name: String = "" … } DeviceRestRepository.kt: package test.domain import org.springframework.data.repository.PagingAndSortingRepository import org.springframework.data.repository.query.Param import org.springframework.data.rest.core.annotation.RepositoryRestResource RepositoryRestResource(collectionResourceRel = "device", path = "device") public trait DeviceRestRepository : PagingAndSortingRepository<Device, Long?> { public fun findByName(Param("name") name: String): […]

Kotlin弹簧安全配置

从1.0.0-beta-242升级到Kotlin 1.0.0-beta-3595后,以下代码不能编译: @Throws(Exception::class) override fun configure(http: HttpSecurity) { http.addFilterBefore(AuthenticationFilter(authenticationManager()), BasicAuthenticationFilter::class.java) http.csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and().authorizeRequests() .antMatchers("/authorization/**", "/public/**").permitAll() .antMatchers("/**").authenticated() } 返回的错误是: SecurityAssembly.kt: (48, 65): Unresolved reference: permitAll 编辑: 来自流行的Spring Security框架的permitAll方法的签名是: public ExpressionInterceptUrlRegistry permitAll() { return access(permitAll); } 我错过了什么或者这是一个错误?

Kotlin编译器返回:未解决的引用:Spring 5.0中的springframework

我试着开始使用Kotlin和Spring 5.0一起玩,但是我遇到了Kotlin编译器没有认识到任何对Spring的引用的问题: [错误]无法执行目标org.jetbrains.kotlin:kotlin-maven-plugin:1.1.1:编译(编译)项目kotlin-mvc-project:编译失败:编译失败: [错误](文件位置):[7,12]未解决的参考:springframework 我正在使用Spring的里程碑版本Spring 5.0.0.M5和Kotlin版本1.1.1(在我的kotlin编译器和IntelliJ Kotlin插件上)。 在我的任何Kotlin文件中,IDE没有强调编译错误,但运行kotlin编译器似乎根本没有看到Spring 5.0。 有没有人有任何想法如何解决这个问题? 我在这个项目中使用Maven,我已经附上了我的POM作为参考: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>kotlin-mvc-project</groupId> <artifactId>kotlin-mvc-project</artifactId> <version>1.0-SNAPSHOT</version> <properties> <kotlin.version>1.1.1</kotlin.version> <spring.version>5.0.0.M5</spring.version> </properties> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-compiler</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> […]

Spring Boot 2和Kotlin(带Maven)

我想使用Spring Boot 2(即暂时构建快照)开始一个新项目,而后者又使用了Spring Framework 5(也是最新的)。 原因是春季5应该有更多的改善Kotlin的支持 ,我想用Kotlin。 现在我找到的例子使用Spring Boot 1.4.3,当然还有Gradle,当然还有基于Kotlin的Gradle文件。 说实话,对于一个单一的项目来说,这对我来说太过于新技术了。 我甚至不知道如何添加一个新的存储库到Gradle(Kotlin-Gradle!)构建脚本。 我更喜欢一个Maven项目,因为我至少熟悉这个,而全新的Spring和Kotlin将会有足够的实验。 那么,如何在Maven中做到这一点? 什么是在那里我看到Gradle引用的kotlin-spring插件?