All Questions
Tagged with spring-boot kotlin
2,559
questions
139
votes
7
answers
69k
views
Spring Boot 2.5.0 generates plain.jar file. Can I remove it?
After the Spring Boot 2.5.0 update, it generates the myprogram-0.0.1-plain.jar file alongside the usual myprogram-0.0.1.jar. Can I disallow gradle to generate the *.plain.jar file? I use Gradle 7.0.2.
...
114
votes
6
answers
226k
views
How to do bulk (multi row) inserts with JpaRepository?
When calling the saveAll method of my JpaRepository with a long List<Entity> from the service layer, trace logging of Hibernate shows single SQL statements being issued per entity.
Can I force ...
69
votes
10
answers
64k
views
Kotlin & Spring Boot @ConfigurationProperties
How to properly initialize ConfigurationProperties in Spring Boot with Kotlin?
Currently I do like in the example below:
@ConfigurationProperties("app")
class Config {
var foo: String? = null
...
69
votes
10
answers
138k
views
springboot Upgrade from 2.3.5.RELEASE to 2.4.1- ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
I am trying to upgrade my kotlin - gradle project from springboot version 2.3.5.RELEASE to 2.4.1. Looks like there is version mismatch between springboot-2.4.1 and sping-cloud-Hoxton.SR9.
build.gradle....
64
votes
4
answers
14k
views
How to do PATCH properly in strongly typed languages based on Spring - example
According to my knowledge:
PUT - update object with its whole representation (replace)
PATCH - update object with given fields only (update)
I'm using Spring to implement a pretty simple HTTP server....
60
votes
12
answers
108k
views
How to log request and response bodies in Spring WebFlux
I want to have centralised logging for requests and responses in my REST API on Spring WebFlux with Kotlin. So far I've tried this approaches
@Bean
fun apiRouter() = router {
(accept(MediaType....
50
votes
9
answers
75k
views
How to log the active configuration in a Spring Boot application?
I would really like to use YAML config for Spring Boot, as I find it quite readable and useful to have a single file showing what properties are active in my different profiles. Unfortunately, I'm ...
41
votes
3
answers
25k
views
Spring Data JPA How to use Kotlin nulls instead of Optional
I'm writing a Spring Boot app with Spring Data JPA and Kotlin, and I've noticed that in CrudRepository there is the following method:
Optional<T> findById(ID id);
I'm using Kotlin, though, ...
31
votes
4
answers
78k
views
How to send request body in spring-boot web client?
I'm facing some problem while sending request body in spring boot web client. Trying to send body like below:
val body = "{\n" +
"\"email\":\"[email protected]\",\n" +
"\"id\":1\n"...
30
votes
6
answers
48k
views
How to generate OpenApi 3.0 spec from existing Spring Boot App?
I have a project (Spring Boot App + Kotlin) that I would like to have an Open API 3.0 spec for (preferably in YAML). The Springfox libraries are nice but they generate Swagger 2.0 JSON. What is the ...
28
votes
4
answers
38k
views
Spring WebFlux throws 'producer' type is unknow when I return value in the response body
I'm using Spring Boot with Kotlin, and now trying to get status value from a GET restful service by passing a handler for a reactive service.
I can see that the handler I'm passing is in the request, ...
27
votes
3
answers
27k
views
Cannot construct Spring webClient due to java.lang.IllegalStateException: No suitable default ClientHttpConnector found
I would like to use a specific WebClient in my service class. I get this exception while constructing it:
It looked like it was a dependency issue but a good old clean-install didn't change anything.
...
26
votes
3
answers
16k
views
Spring Boot @Autowired with Kotlin in @Service is always null
Currently I try to rewrite my Java Spring Boot Application with Kotlin. I encountered a problem that in all of my classes which are annotated with @Service the dependency injection is not working ...
25
votes
3
answers
17k
views
bean validation not working with kotlin (JSR 380)
so first of all i could not think of a better title for this question so i'm open for changes.
I am trying to validate a bean using the bean validation mechanism (JSR-380) with spring boot.
So i got ...
23
votes
5
answers
5k
views
How to enable spring security kotlin DSL?
How can we enable support for the spring security kotlin DSL?
As you can see from the Screenshot of the IDE (IntelliJ), the DSL is not available:
This is the full SecurityConfig.kt file:
package com....
22
votes
3
answers
55k
views
Spring - server.connection-timeout not working
In my application.properties file I have...
server.port=8086
server.connection-timeout=15000
I know that the file is being loaded correctly because the server is running on port 8086.
In the ...
21
votes
4
answers
59k
views
WebFlux functional: How to detect an empty Flux and return 404?
I'm having the following simplified handler function (Spring WebFlux and the functional API using Kotlin). However, I need a hint how to detect an empty Flux and then use noContent() for 404, when the ...
21
votes
6
answers
77k
views
Spring Boot JPA@CreatedDate @LastModifiedDate not being populated when saving the object
I am writing an app with Spring Boot + JPA, using a Postgres database. I have a User Entity and I am trying to get a timestamp when the user record is saved and/or modified. This is not working. The ...
20
votes
1
answer
5k
views
Kotlin + Gradle Unresolved Reference
As per this question I'm trying to setup the following project structure
project/
settings.gradle
projectB/ # some common code (using spring-boot)
build.gradle
com/
foo/...
19
votes
6
answers
16k
views
IntelliJ Idea 2017.3 unable to start Kotlin Spring Boot App - @Configuration class may not be final
I was able to launch a Spring Boot Kotlin App from IntelliJ 2017.3. After the last IntelliJ fix update I cannot start that application from the IDE, getting this exception:
org.springframework.beans....
19
votes
4
answers
12k
views
How to use "Functional bean definition Kotlin DSL" with Spring Boot and Spring WebFlux?
At https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/kotlin/org/springframework/context/support/BeanDefinitionDsl.kt the comment shows how to define Spring Beans ...
19
votes
3
answers
13k
views
spring-configuration-metadata.json file is not generated in IntelliJ Idea for Kotlin @ConfigurationProperties class
I'm trying to generate spring-configuration-metadata.json file for my Spring Boot based project. If I use Java @ConfigurationProperties class it is generated correctly and automatically:
@...
19
votes
2
answers
3k
views
Mongo driver with @Testcontainers, throws exceptions after tests run successfully
I'm setting up integration tests in a sample spring boot kotlin project, using testcontainers:mongodb.
I've set up a MongoDBContaine, and everything works as expected - the app connects to the mongodb ...
18
votes
4
answers
28k
views
Kotlin best way to log using slf4j
I have an spring boot project with default log configuration using logback. I have always used this approach for logging purpose inside my applications:
logger.info("Get user paginated: filter {}",...
18
votes
6
answers
29k
views
Programmatically restart Spring Boot application / Refresh Spring Context
I am trying to programmatically restart my Spring Application without having the user to intervene.
Basically, I have a page which allows to switch the mode of the application (actually meaning ...
17
votes
2
answers
23k
views
What are the http codes to automatically retry the request?
I am using the mix Spring-Cloud + feign + spring-retry to help retry requests on the client side (all are Kotlin-based back-ends)
My spring-boot conf is like this:
myApp:
ribbon:
...
17
votes
1
answer
6k
views
Spring R2DBC DatabaseClient.as(…)
In my spring-boot 2.3 application, I have a simple data method using DatabaseClient:
fun getCurrentTime(): Mono<LocalDateTime> =
databaseClient
.execute("SELECT NOW()")
...
16
votes
2
answers
16k
views
Error: Getters of lazy classes cannot be final Kotlin Spring Boot
I try to create REST Spring Boot Server on Kotlin.I used database - first and automatically generated entities using the built-in Intellij tool. When starting the server pop-up error:
2020-01-12 15:...
15
votes
2
answers
11k
views
Create instance of Spring´s ParameterizedTypeReference in Kotlin
I am trying to learn Kotlin, and test how it works with spring boot. My application is using a mongo database to store data and I have a Jersey resource for retrieving data. I am testing it using ...
15
votes
5
answers
19k
views
Spring Boot 2 Gradle plugin without executable jar
How do I configure Spring Boot Gradle plugin 2 to disable the Boot distribution in Gradle Script Kotlin.
The distribution i want is a assembly bundle zip with all dependencies (and the jar) in the ...
15
votes
2
answers
7k
views
Returning Flux<String> from Spring WebFlux returns one string instead of array of strings in JSON
new to Spring WebFlux, trying to return array of strings in one endpoint and for some reason it returns one concatenated string istead of JSON array.
Wrapping it with some class solves the problem ...
15
votes
3
answers
7k
views
Cannot access 'java.lang.Object' which is a supertype of 'org.gradle.api.artifacts.dsl.DependencyHandler'
Why is my build.gradle.kts file looking like this? This is a fresh Spring Boot project generated with start.spring.io. I already tried invalidate caches / restart, rebuild, resyncing and nothing works....
15
votes
1
answer
20k
views
WebClient's bodyToMono on Empty Body Expected Behavior
What is the expected behavior when WebClient bodyToMono encounters an empty body? In my specific example we are checking the status returned from a post call, and if it's an error converting it to our ...
15
votes
1
answer
35k
views
How to enable Bearer authentication on Spring Boot application?
What I am trying to achieve is:
users, authorities, clients and access tokens stored in a database (i.e. MySQL) accessed via jdbc
API exposes endpoints for you to ask "can I have an OAuth2 bearer ...
14
votes
5
answers
19k
views
EnableEurekaClient import doesn't exist
I added spring-cloud-starter-netflix-eureka-client gradle depedency in
my project and shrik the depedency. But when go use
@EnableEurekaClient in my Main class it show me suggestion create
@...
14
votes
1
answer
10k
views
'one to many' / 'many to many' attribute value type should not be '? extends'
I'm trying to define a simple Hibernate Mapping using Annotations in Kotlin. But my Many-To-Many Relation is not working as expected. Causing the following error in IntelliJ IDEA:
'one to many' / '...
14
votes
7
answers
24k
views
Spring boot @Valid on requestBody in controller method not working
I am trying to validate a simple request body annotated by @Valid annotation in a @RestController annotated by @Validated. Validations are working correctly on primitive variable in request (on age in ...
14
votes
3
answers
9k
views
Spring Boot: Change property placeholder signifier
What is the easiest way to change the prefix and suffix for the property placeholder in Spring Boot?
The default is @Value("${some.property}"), however this looks ugly in Kotlin, since it needs to ...
14
votes
2
answers
13k
views
spring.config.location not working on spring boot 2.0.0 M6
I'm migrating one of my micro-services to Spring Boot 2.0.0.M6 and I got and error while using the --spring.config.location= option on the command line. The error is the following:
Caused by: java....
13
votes
2
answers
11k
views
Kotlin Spring boot @ConfigurationProperties for list
I want to read the yaml config files using Kotlin and below is my code:
application.yml
message:
messages:
- name: abc
type: aaa
size: 10
- name: xyz
type: bbb
size: ...
12
votes
2
answers
12k
views
I can't exclude MongoAutoConfiguration in Springboot-Kotlin (MongoSocketOpenException)
I'm getting a MongoSocketOpenException when trying to exclude MongoAutoConfiguration. I'm trying to connect to a remote MongoDB. Is the @EnableAutoConfiguration syntax correct considering I'm working ...
12
votes
4
answers
14k
views
Spring WebMvcTest with post returns 403
I'm wondering where the issue is with my code, every time I run a post test (irrespective of what controller it targets, or method), I return a 403 error, when in some cases I expect a 401, and in ...
12
votes
1
answer
9k
views
Spring Boot: Boot Run cannot add addResources = true
In Kotlin, on Intellij using gradle to run the task bootRun for Spring Boot, I get the error that follows:
BUILD FAILED
Total time: 0.085 secs
Could not set unknown property 'addResources' for ...
12
votes
4
answers
16k
views
How to log stack trace using kotlin.logging?
I am using kotlin.logging as my logging framework for an application.
I would like to be able to log the stack trace in a much more readable way (maybe JSON format):
I am doing the following, but it ...
12
votes
2
answers
20k
views
What are the differences using spring boot with Kotlin and with Java?
What are the differences using spring boot with Kotlin and with Java?
Kotlin is among the three languages you could choose to start your app with https://start.spring.io. So it's supported by the ...
12
votes
2
answers
5k
views
Plugin not found: jpa
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<args>
<arg&...
12
votes
1
answer
8k
views
Registering test bean with same name in Spring Framework 5.1 [duplicate]
I'm having following config in my production files:
@Configuration
internal class Config {
@Bean
fun clock() = Clock.systemUTC()
}
In tests:
@Configuration
class ClockTestConfiguration {
@...
12
votes
3
answers
28k
views
Spring WebFlux: Only one connection receive subscriber allowed
I am writing a simple app with Spring 5 Webflux and Kotlin. I am trying to implement PUT endpoint in a following way:
PUT("/confs/{id}", {
val id = it.pathVariable("id")
ServerResponse.ok()....
12
votes
1
answer
12k
views
How to set a custom Feign RequestInterceptor for specific clients?
I need to add custom Authorization header to some new feign clients. So I write an RequestInterceptor and it worked but the point is I don't want this custom RequestInterceptor affect my old clients. ...
12
votes
1
answer
18k
views
@Autowired lateinit property '' has not been initialized
I'm trying to create a web project using Spring-boot + Vaadin and i want to use spring-data-jpa with hibernate to fetch the data from PostgreSQL database.
In my Vaadin's view i try to autowire my ...