Tiago
01/16/2023, 5:23 PM@ConfigurationProperties("application.custom.properties")
data class SomeProperties(
val foo: Long,
val bar: String,
)
application.properties:
application.custom.properties.foo=1
application.custom.properties.bar=Text Here
ok, so I have another class, just a POJO, and need to get the values from that configuration properties bean
data class ObjectBuilder(
var fooValue: Long = SomeProperties.foo,
var barValue: String = SomeProperties.bar,
)
is there a way of getting the SomeProperties values on a non spring context?sdeleuze
01/16/2023, 6:23 PMkotlinx.metadata.jvm
instead of kotlin-reflect
and jackson-module-kogera
to get some data points on before/after https://github.com/spring-projects/spring-framework/issues/21546#issuecomment-1384418132Alexandre A Barbosa
01/16/2023, 8:02 PM@KafkaListener
annotation and when I run the functional tests, I produce a protobuf topic message and the listener works properly to consume that message.
But my unit test need to test this method, and I am using this:
@Autowired
lateinit var ingestionListener: IngestionConsumerListener
to inject my listener and I want to test this method but without the Kafka in memory.
But the test is trying to load the Kafka because I am getting this:
Could not resolve placeholder 'ingestion.config.topic.name' in value "#{'${ingestion.config.topic.name}'}"
that is used in my implementation:
@KafkaListener(
id = "ingestionListener",
topics = ["#{'\${ingestion.config.topic.name}'}"],
groupId = "#{'\${ingestion.consumer.group.id}'}",
concurrency = "#{'\${ingestion.config.consumer.concurrency}'}"
)
fun consumeIngestion(ingestionHttpRequest: ConsumerRecord<String, IngestionHttpRequest.HttpRequest>)
I am trying to use this kind of solution for my first unit test using Kotlin and Kafka:
@EnableAutoConfiguration(exclude = [KafkaAutoConfiguration::class])
but I am still struggling with the error above…
Please any suggestion to fix that? How to test a kafka listener using Java/Kotlin without Kafka in memory?
Issue: FIXED! I only needed to add all properties necessary for the UT and Kafka is not necessary at memoryShumilin Alexandr
01/17/2023, 10:32 AMdata class EmailVerificationStateRequestDto (
@field:NotBlank(message = "parameterName не указан")
@field:Size(min = 6, max = 6, message = "parameterName должен содержать 6 алфавитно-цифровых символов" )
@field:Pattern(regexp = "^[a-zA-Z0-9]+\$")
val parameterName: String?,
val email: String?
)
three validation for one field
and i have this class where i can get some information about error
p.s. service vy webFlux, Mono, Flux, Reactive
@ExceptionHandler(WebExchangeBindException::class)
fun handleException(bindException: WebExchangeBindException): ResponseEntity<String> {
val validationError = ValidationError(
bindException.fieldError?.defaultMessage
?: throw RuntimeException("Something wrong with validation error message")
)
return ResponseEntity.badRequest().body(objectMapper.writeValueAsString(validationError))
}
when i call controller method and set parameterName = “” i got 3 errors,
i want get 1 error NotBlank only, not all 3 validations, how can i do this?George
01/18/2023, 3:44 PMNo accessor to set property @org.springframework.data.annotation.Id() @org.springframework.data.relational.core.mapping.Column(value="id")private final int org.msensis.imahub.hub.core.internal.entities.MessageEntity.id
java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id() @org.springframework.data.relational.core.mapping.Column(value="id")private final int org.msensis.imahub.hub.core.internal.entities.MessageEntity.id
While using data classes for entities? Thanks in advance for any answersYogeshvu
01/20/2023, 11:59 PMDariusz Kuc
01/26/2023, 2:03 AMsdeleuze
01/31/2023, 10:04 AMAlina Dolgikh [JB]
Manasseh
02/07/2023, 3:05 PMdany giguere
02/11/2023, 1:50 PMYogeshvu
02/16/2023, 5:08 PMhantsy
02/19/2023, 6:14 AM// trigger a scheduled task to parse cvs
// aList is parsed from a cvs file.
aList.forEach{
// use it.refId to query extra record from our database.
val extra = repository.findByRefId(it.refId)
if(it.status == 'error'{
//do some update on extra by it.status condition
extra.status = 'error'
repository.save(extra) // A kotlin coroutines repository
}
}
// in the last scheduled task, only one status(error) is needed to updated
// but finally after the iteration, all records are updated the error status
igor.wojda
02/22/2023, 11:46 AMService
is equivalent of UseCase
(Clean Architecture)?Aaron Shakib
02/22/2023, 11:31 PMAaron Shakib
02/26/2023, 7:57 PMigor.wojda
02/27/2023, 1:42 PMdata class Task(val name: String, val description: String)
class CreateTeskUseCase(val repository: Repository) {
fun execute(taskRequestModel: TaskRequestModel) {
val task = Task(taskRequestModel.name, taskRequestModel.description)
//...
repository.save(task)
}
}
This works fine, but when I want to test interaction with the repo the "dummy" factory is required to get testable Task
instance:
class CreateTeskUseCase(val repository: Repository, val taskFactory: TaskFactory) {
fun execute(taskRequestModel: TaskRequestModel) {
val task = taskFactory.create(taskRequestModel.name, taskRequestModel.description)
//...
repository.save(task)
}
}
class TaskFactory {
fun create(name: String, description: String) = Task(name, description)
}
I wonder if there is a way to generate this TaskFactory
class (perhaps using ksp
). Something like this @GenerateFactory
annotation?
@GenerateFactory
data class Task(val name: String, val description: String)
igor.wojda
03/02/2023, 7:45 AMCould not autowire No beans of "TaskRepository" found
warning in the UpdateTaskDescriptionUseCase
class (attached image):
Here is repo class:
@Repository
class TaskRepository {
// ...
}
The warning seems to be a false positive because the above code works fine (the repo class is injected into the use case)
I wonder whats the desired solution is here. Do I need another annotation together with the repo annotation?Cru
03/02/2023, 5:31 PM@Component
annotations work with kotlin objects and automatically make that bean a singleton?
I typically create a wrapper class to annotate as @Component
to wrap my kotlin objects.kubele
03/09/2023, 10:59 AMScheduled
annotation with suspend function without wrapping it to a runBlocking block?igor.wojda
03/09/2023, 5:28 PMkqr
03/09/2023, 10:33 PMasavio
03/12/2023, 4:01 AMjava.lang.IllegalArgumentException: Attempt to execute an operation that requires a primary index without defining any primary key attributes in the table metadata.
. I define partition key in the data class. But it keeps complaining that I don’t have it!. Here’s the entire code:
package com.redacted.backend.monolith.app.controllers
import com.redacted.backend.monolith.config.dynamodb.createDynamoDbClient
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.stereotype.Controller
import org.springframework.stereotype.Repository
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient
import software.amazon.awssdk.enhanced.dynamodb.TableSchema
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey
@Controller
class DogController(private val repo: DogRepository) {
@MutationMapping
fun createDog(@Argument dog: Dog): String {
return repo.create(dog)
}
}
@DynamoDbBean
data class Dog(
@get:DynamoDbPartitionKey
val dogId: String? = null,
@get:DynamoDbSortKey
val rating: Int = 0,
val name: String? = null
)
@Configuration
class DynamoClient(
@Value("aws.dynamodb.access-key") private val dynamoDbAccessKey: String,
@Value("aws.dynamodb.secret-key") private val dynamoDbSecretKey: String,
@Value("aws.dynamodb.region") private val dynamoDbRegion: String
) {
@Bean
fun dynamoDbClient(): DynamoDbEnhancedClient = createDynamoDbClient(
accessKey = dynamoDbAccessKey,
secretKey = dynamoDbSecretKey,
region = dynamoDbRegion
)
}
@Repository
class DogRepository(private var client: DynamoDbEnhancedClient) {
private val table = client.table("dog_table", TableSchema.fromBean(Dog::class.java))
fun create(dog: Dog): String {
table.putItem(dog)
println("Written the dog to db successfully!")
return "Written"
}
}
Here’s the whole error: Any help would be very much appreciated!
Error message is in the 🧵Pihentagy
03/16/2023, 1:40 PMpublic enum class Gender(@JsonValue val value: String) {
MALE("m"), FEMALE("f");
}
The controller:
@GetMapping("/test", produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE])
fun gender(@RequestParam gender: Gender): Map<String, Gender> =
when (gender) {
Gender.MALE -> mapOf("result" to Gender.FEMALE)
Gender.FEMALE -> mapOf("result" to Gender.MALE)
}
For GET localhost:8080/test?gender=m
I expect to get {"result": "f"}
.Pihentagy
03/17/2023, 2:15 PMdocker run --user $(id -u) --volume "$PWD":/home/gradle/project --workdir /home/gradle/project gradle:7-jdk17 gradle --no-daemon --no-rebuild --no-scan --no-watch-fs --no-parallel bootRun
(to which channel does this question fit?)Jon Senchyna
03/17/2023, 2:59 PMobject
as a bean in Spring and am wondering if there's a simpler way to do this. Why I'm doing this is a long story.
What I've tried so far:
1. Annotate my object with @Component
(results in Spring creating a second instance of my object)
2. Create a separate @Configuration
class and expose my object as an @Bean
in a method in there.Emil Kantis
03/27/2023, 1:30 PMPedro Sousa
03/30/2023, 8:50 AM@RestController
class TestController(val tracer: Tracer) {
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
@GetMapping("/test")
suspend fun test() {
<http://logger.info|logger.info>("before: ${tracer.currentTraceContext().context()?.traceId()}")
delay(50)
<http://logger.info|logger.info>("after: ${tracer.currentTraceContext().context()?.traceId()}")
}
}
The second log statement reports a null value for the traceId, because the Kotlin delay
function caused a thread switch and the trace informations is lost,
Can anyone help here? Why is this happening? Is it by design? Is there something I can do to guarantee that the traceId is always present?mbonnin
04/03/2023, 1:09 PMorg.jetbrains.kotlin.plugin.spring
plugin? My understanding is that the beans DSL removes some proxying so it might not require open classes? But I'm stuck at @SpringBootApplication
because I haven't found a non-annotated equivalent.sdeleuze
04/04/2023, 3:59 PM