Spring boot @Spring Boot 2.5.0忽略了列(Cassandra)注释(适用于2.4.6)
在尝试使用spring boot starter数据cassandra将项目从spring bootSpring boot @Spring Boot 2.5.0忽略了列(Cassandra)注释(适用于2.4.6),spring-boot,kotlin,cassandra,Spring Boot,Kotlin,Cassandra,在尝试使用spring boot starter数据cassandra将项目从spring boot2.4.6更新为2.5.0时,我遇到了一个问题,即忽略了我的@列注释 使用以下注释 @列(“blabla”) 瓦尔·布兹:长 导致此错误的原因: Query; CQL [INSERT INTO bar (baz,buz) VALUES (?,?)]; Undefined column name buz; nested exception is com.datastax.oss.driver.ap
2.4.6
更新为2.5.0
时,我遇到了一个问题,即忽略了我的@列
注释
使用以下注释
@列(“blabla”)
瓦尔·布兹:长
导致此错误的原因:
Query; CQL [INSERT INTO bar (baz,buz) VALUES (?,?)]; Undefined column name buz; nested exception is com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: Undefined column name buz
因此,查询使用buz
而不是预期的blabla
。弹簧靴2.4.6
而不是2.5.0
工作正常。有什么变化,所以我需要调整我的代码,还是这是一个错误
问题似乎来自于spring数据cassandra
,它使用spring引导进行更新
- 使用Spring Boot
和2.4.6
一切正常实现(group=“org.springframework.data”,name=“Spring data cassandra”,version=“3.1.9”)
- 使用Spring Boot
和2.4.6
会失败实现(group=“org.springframework.data”,name=“Spring data cassandra”,version=“3.2.0”)
@列
注释都被忽略了,因为在添加它时也没有使用forceQuote=true
可以使用以下最小示例(docker build.
)重现错误:
Dockerfile
build.gradle.kts
src/main/kotlin/com/acme/Application.kt
src/test/kotlin/com/acme/integration/TestFullStack.kt
src/test/resources/cql/foo.cql
好的,问题似乎在于构造函数中已经声明了
Bar
的成员。也就是说,替换这个
@表格(“条形图”)
分类栏(
@PrimaryKey(“baz”)
瓦尔·巴兹:很长,
@列(“blabla”)
瓦尔·布兹:长
)
有了这个
@表格(“条形图”)
类栏(baz:Long,buz:Long){
@PrimaryKey(“baz”)
val baz:Long=baz
@列(“blabla”)
val buz:Long=buz
}
使它再次工作
使用
org.springframework.data的3.1.9
版本:spring数据cassandra
两者都运行良好,但第一个版本在更新到3.2.0
时会中断。我们打开了一个问题:您正在使用org.jetbrains.kotlin:kotlin reflect:1.4.31
和1.5.0版本的kotlin插件。也许这打破了注释处理的魔法(依赖于反射)?@Мааааааааааафааааааааааааааа107带有val kotlinVersion=“1.5.0”
)val pluginKotlinVersion=“1.4.31”
只是用于Gradle插件的版本。我刚刚将两者都更新为1.5.10
(并相应地调整了我问题中的代码),但结果没有什么不同。
FROM openjdk:11-jdk-slim
WORKDIR /home/test
ADD . /home/test
RUN ./gradlew test
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val kotlinVersion = "1.5.10"
val springBootVersion = "2.4.6"
plugins {
val pluginKotlinVersion = "1.5.10"
val pluginSpringBootVersion = "2.5.0"
id("org.springframework.boot") version pluginSpringBootVersion
kotlin("jvm") version pluginKotlinVersion
kotlin("plugin.spring") version pluginKotlinVersion
kotlin("plugin.jpa") version pluginKotlinVersion
}
group = "com.acme"
version = "1.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation(
group = "org.springframework.boot",
name = "spring-boot-starter-data-cassandra",
version = springBootVersion
)
// 3.1.9 -> fine
// 3.2.0 -> broken
// 3.2.1 -> broken
implementation(group = "org.springframework.data", name = "spring-data-cassandra", version = "3.2.0")
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web", version = springBootVersion)
implementation(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = kotlinVersion)
implementation(
group = "org.cassandraunit",
name = "cassandra-unit-spring",
version = "4.3.1.0"
) {
exclude(group = "org.hibernate")
testImplementation(group = "com.google.guava", name = "guava") {
version {
// https://github.com/jsevellec/cassandra-unit/issues/248
// https://issues.apache.org/jira/browse/CASSANDRA-15245
strictly("18.0")
}
}
}
testImplementation(
group = "org.springframework.boot",
name = "spring-boot-starter-test",
version = springBootVersion
)
}
tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
withType<Test> {
testLogging.exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
rootProject.name = "acmetest"
package com.acme
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.data.cassandra.core.mapping.Column
import org.springframework.data.cassandra.core.mapping.PrimaryKey
import org.springframework.data.cassandra.core.mapping.Table
import org.springframework.data.cassandra.repository.CassandraRepository
import org.springframework.stereotype.Repository
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}
@Table("bar")
class Bar(
@PrimaryKey("baz")
val baz: Long,
@Column("blabla")
val buz: Long
)
@Repository
interface BarRepository : CassandraRepository<Bar, Long>
spring:
data:
cassandra:
contact-points: localhost
port: 9142
keyspace_name: foo
local-datacenter: datacenter1
package com.acme.integration
import com.acme.Bar
import com.acme.BarRepository
import org.cassandraunit.spring.CassandraDataSet
import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener
import org.cassandraunit.spring.EmbeddedCassandra
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.TestExecutionListeners
import org.springframework.test.context.junit4.SpringRunner
@ActiveProfiles("test")
@RunWith(SpringRunner::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestExecutionListeners(
listeners = [CassandraUnitDependencyInjectionTestExecutionListener::class],
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)
@CassandraDataSet(value = ["cql/foo.cql"], keyspace = "foo")
@EmbeddedCassandra
class TestFullStack {
@Autowired
lateinit var barRepository: BarRepository
@Test
fun `test init`() {
barRepository.save(Bar(1, 2))
}
}
DROP KEYSPACE IF EXISTS foo;
CREATE KEYSPACE foo WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':1};
CREATE TABLE foo.bar
(
baz bigint,
blabla bigint,
PRIMARY KEY (baz)
);