https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
spring
  • d

    dodalovic

    11/11/2020, 2:48 PM
    If I have this as my configuration properties:
    kotlin
    @ConstructorBinding
    @ConfigurationProperties("company")
    class UsersProperties(val users: Map<String, User>) {
        data class User(
            val password: String,
            val companyName: String,
            val accounts: List<String>
        )
    }
    and this in my application.yaml
    yaml
    company:
      users:
        <mailto:admin@email.com|admin@email.com>:
          password: admin
          companyName: Company 1
          accounts: [ "ACC1", "ACC2" ]
        <mailto:user@user.com|user@user.com>:
          password: user
          companyName: Company 2
          accounts: [ "ACC3", "ACC4" ]
    spring complains that
    users
    property can't be null Any idea? Thanks in advance
    j
    • 2
    • 2
  • d

    dodalovic

    11/12/2020, 10:45 AM
    Hi I'm writing an API in Spring boot / kotlin / functional router (
    coRouter
    ) with coroutines ... Can someone point me to Spring security configuration for such a stack? Thanks! I'm using pretty much the latest Spring Boot
    r
    • 2
    • 3
  • e

    Evgeniy Zaharov

    11/12/2020, 11:51 AM
    Hi, mb in this channel somebody could help me 😃 https://kotlinlang.slack.com/archives/C1CFAFJSK/p1605103613045600 I have a problem with retrieving a reactor context in suspend function (in general in spring webflux in route suspend function). Base example from docs doesn’t work, but I found that context could be retrieved by
    val context = Mono.deferWithContext { ctx -> Mono.just(ctx) }.awaitFirst()
    . Is it a right solution ?
    n
    • 2
    • 2
  • r

    Robert Jaros

    11/12/2020, 6:19 PM
    Spring Boot 2.4.0 reference documentation doesn't say a word about kotlinx.serialization support. Is it supported? How to use it?
    c
    s
    • 3
    • 5
  • r

    Robert Jaros

    11/12/2020, 6:19 PM
    https://docs.spring.io/spring-boot/docs/2.4.0/reference/html/spring-boot-features.html#boot-features-json
    s
    • 2
    • 1
  • j

    Jonas Bark

    11/12/2020, 9:09 PM
    class reactor.core.publisher.MonoOnErrorResume cannot be cast to class org.springframework.web.servlet.function.ServerResponse (reactor.core.publisher.MonoOnErrorResume and org.springframework.web.servlet.function.ServerResponse are in unnamed module of loader ‘app’)
    Anyone else got this during unit tests when using runBlocking after updating to Spring Boot 2.4.0? I’m currently investigating why all tests fail once runBlocking is used.
    d
    • 2
    • 3
  • j

    jbnizet

    11/15/2020, 8:00 PM
    If you use Kotlin and MockK and want to enjoy nested Spring Boot tests, I just released SpringMockK 3.0.0. https://github.com/Ninja-Squad/springmockk/releases/tag/3.0.0.
    🎉 8
    n
    d
    • 3
    • 3
  • j

    Júlio Santos

    11/19/2020, 5:53 PM
    Speak personal, all right? Does anybody have an example of a project with coroutines with Spring? If someone helps me I will be grateful...😀
    r
    n
    t
    • 4
    • 6
  • r

    rajesh

    11/20/2020, 6:56 AM
    Hi, how can I implement spring security with jwt in rest api without using role (only user)? Passing authories as
    null
    in
    UsernamePasswordAuthenticationToken(userDetails, "", userDetails.authorities)
    gives error as authorities can not be null . Any tutorial or help is appreciated.
    j
    a
    a
    • 4
    • 12
  • q

    Qria

    11/21/2020, 2:47 PM
    Hello, I'm a former python webdev new to kotlin trying to get started on spring boot. However, I find the resources severely lacking. There were a single kotlin spring boot documentation in the official tutorials and I have failed to follow through because it omitted a lot of import statements( in which I only can guess that it should be obvious from the context). Now I am curious, is it possible to learn spring boot right away with kotlin or should I go learn spring boot in java and try to translate that into kotlin?
    r
    a
    +3
    • 6
    • 7
  • k

    Kush Patel

    11/23/2020, 3:49 AM
    I can render the
    index.html
    when I visit
    <http://localhost:8080/index.html>
    but what I would like to do is render the
    index.html
    when I visit
    <http://localhost:8080/>
    . Any insight would be helpful. Thanks!
    s
    • 2
    • 29
  • g

    gbaldeck

    11/24/2020, 8:44 PM
    has anyone successfully been able to use the spring boot gradle plugin in a kotlin multiplatform project?
    a
    r
    • 3
    • 3
  • r

    ReddyTintaya

    11/25/2020, 7:21 PM
    hi everyone, any book that you can recommend me about spring boot with kotlin?
    b
    j
    s
    • 4
    • 5
  • m

    Manuel Lorenzo

    11/27/2020, 8:55 AM
    Maybe not the type of questions for this channel but does anybody know of a course where we can learn from the basics to advance spring boot but with Kotlin? All there is is java 😞
    t
    • 2
    • 4
  • p

    Philipp Mayer

    11/27/2020, 8:12 PM
    Hey everyone, maybe there's someone who can guide me to the solution of the following problem: Let's say I have the following dto defined:
    @Serializable
    class RouteDto(
            val id: Int? = null,
            val template: Template?,
            val server: Server?,
            val variables: List<Variable>,
            val name: String,
            val active: Boolean,
            val profile: Profile,
            val description: String
    )
    And I have the following endpoint:
    @RestController
    @RequestMapping("/routes")
    class RouteController(
        @PostMapping("/new")
        fun createRoute(routeDto: RouteDto): ResponseEntity<RouteDto?> {
            val route = saveRouteService.saveRouteFrom(routeDto)
            val dto: RouteDto = route.id?.toDto() ?: return ResponseEntity.unprocessableEntity().build()
    
            return ResponseEntity.ok(dto)
        }
    Now I just wanted to call it like that with mockMvc:
    @Test
        fun `should create a route`() {
            val dto = RouteDto(null, null, null, listOf(),"testDto", true, Profile.DEV, "should create a route test")
            <http://mockMvc.post|mockMvc.post>("/routes/new") {
                contentType = MediaType.APPLICATION_JSON
                content = Json.encodeToString(dto)
            }.andExpect {
                status { is2xxSuccessful() }
            }
        }
    However, I get the following Warning:
    DefaultHandlerExceptionResolver : Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
    Field error in object 'routeDto' on field 'active': rejected value [null]; codes [typeMismatch.routeDto.active,typeMismatch.active,typeMismatch.boolean,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [routeDto.active,active]; arguments []; default message [active]]; default message [Failed to convert value of type 'null' to required type 'boolean'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [null] to type [boolean] for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type]]
    Spring seems to fail at reading the Boolean value
    active
    , which is actually correctly serialized:
    MockHttpServletRequest:
          HTTP Method = POST
          Request URI = /routes/new
           Parameters = {}
              Headers = [Content-Type:"application/json;charset=UTF-8", Content-Length:"136"]
                 Body = {"template":null,"server":null,"variables":[],"name":"testDto","active":true,"profile":"DEV","description":"should create a route test"}
        Session Attrs = {}
    It would be great if someone could point me in a helpful direction. Thanks in advance!
    k
    j
    m
    • 4
    • 7
  • t

    thana

    12/08/2020, 12:44 PM
    Or on the contrary: which dependency MUST NOT be found on the calsspath in order for webflux/coroutines to work properly?
    j
    • 2
    • 2
  • m

    Manuel Lorenzo

    12/09/2020, 9:01 AM
    I’m trying to set up a data source for a H2 embedded database in a Spring project, but when I try to log in via https://localhost:8080/h2-console there’s no way I can log in as it says the DB is not created. Nevertheless when I type the properties manually in the 
    application.properties
     it works 😞. Also, I’d like to insert some data into a table in that DB as soon as the app is started. I created some insert statements into a 
    data.sql
     file in the 
    resources
    file but I nothing is inserted (edited)
    :stackoverflow: 1
    :kotlin-flag: 1
    b
    m
    • 3
    • 3
  • s

    Subhanshu

    12/10/2020, 5:02 PM
    Is there a single resource for learning Spring?
    :kotlin-flag: 1
    k
    s
    • 3
    • 2
  • t

    thana

    12/11/2020, 11:34 AM
    is there any documentation on how to fully use coroutines+Spring (reactive)? What i do know is that in principal everything should work. but when it comes to db transactions or spring security i feal unsure about how to handle the reactor Context, how it interacts with the corouting context and what i do have to do in order everything works or what does already work ootb.
    👍 1
    n
    j
    +2
    • 5
    • 16
  • s

    Saharath Kleips

    12/15/2020, 6:01 PM
    Hoping someone might be able to help identify the reason why this code might be breaking. I’m trying to use the
    ReactiveRedisTemplate
    from the reactive Redis starter.
    val template = ReactiveStringRedisTemplate(connectionFactory)
    template.opsForValue().get("123").subscribe { println("get: $it") } // works! prints: "get: ..."
    
    runBlocking {
      val value = template.opsForValue().get("123").awaitFirst() // fails! connection timeout????
      println("get: $value")
    }
    I’m not sure if this is a coroutines specific issue but
    awaitFirst
    works when converting other fluxes.
    • 1
    • 1
  • m

    manlan

    12/16/2020, 3:18 PM
    What's the best resource to get started with Spring Boot in Kotlin? (I'm brand new to Spring)
    n
    d
    • 3
    • 4
  • t

    thana

    12/16/2020, 4:11 PM
    How do replace kotlinx.serialization with jackson again?
    s
    • 2
    • 14
  • t

    tvtan

    12/17/2020, 10:44 AM
    Hi, I'm using #kotlinx-datetime in Spring, how can I write a converter to convert an
    Instant
    or
    LocalDateTime
    to mysql Datetime and Timestamp?
    k
    • 2
    • 4
  • v

    vilmos.nagy

    12/17/2020, 4:38 PM
    hi there, I'm trying to use the kotlin-coroutines with Spring Boot, and everything seems to work nice util I add the
    @Transactional
    annotation to one of my spring service's method. After the annotation is added some classCastException is thrown, see the details here: https://stackoverflow.com/questions/65331458/classcastexception-monoonerrorresume-cannot-be-cast-to-class-io-ebean-query Is there a howto on how to use the kotlin-coroutines with spring transactions? thanks,
    s
    • 2
    • 15
  • t

    tvtan

    12/18/2020, 3:20 AM
    I'm using spring webflux
    WebFilter
    with kotlin coroutines, currently the only way I can run
    suspend function
    in
    filter
    function is using
    runBlocking
    . Is there a better way for calling a suspend function in that case?
    d
    • 2
    • 4
  • s

    sdeleuze

    12/18/2020, 2:44 PM
    This is not a small change and no promise we will do it, but if enough people push for it we may consider it, so please add your 👍 if you care https://github.com/spring-projects/spring-framework/issues/21546
    👍 4
    r
    • 2
    • 6
  • m

    marzelwidmer

    12/18/2020, 5:31 PM
    Hello have somebody maybe already a spring boot starter with kotlin
    1.4.21
    and spring
    2.4.1
    on place.. with kotlin gradle .
    kts
    I am new in gradle
    r
    s
    • 3
    • 11
  • n

    nathan

    12/20/2020, 1:57 AM
    Any other platform to deploy spring boot app for free besides Heroku?
    m
    c
    • 3
    • 3
  • ł

    Łukasz Bednarczyk

    12/21/2020, 7:36 PM
    Hi! I’m new in spring and I need advice. 🙏 I have a user (entity) which has many user cards (entities). I need to implement authentication and authorization. A user has one user card in an organization, which store his permissions. What should extend of UserDetails - User or UserCard? 🙏
    a
    • 2
    • 1
  • i

    Ivan Pavlov

    12/24/2020, 3:38 PM
    Hi! I'm trying to replace spring security config with new dsl:
    http.cors().configurationSource { CorsConfiguration().applyPermitDefaultValues() }
    However MVC dsl for CORS doesn't contain an ability to set configuration source (
    CorsDsl
    ). I can see that in WebFlux version (
    ServerCorsDsl
    ) there is
    var configurationSource: CorsConfigurationSource? = null
    Does anyone know why there is no such property for MVC?
    j
    • 2
    • 6
Powered by Linen
Title
i

Ivan Pavlov

12/24/2020, 3:38 PM
Hi! I'm trying to replace spring security config with new dsl:
http.cors().configurationSource { CorsConfiguration().applyPermitDefaultValues() }
However MVC dsl for CORS doesn't contain an ability to set configuration source (
CorsDsl
). I can see that in WebFlux version (
ServerCorsDsl
) there is
var configurationSource: CorsConfigurationSource? = null
Does anyone know why there is no such property for MVC?
j

Joris PZ

12/26/2020, 8:04 AM
That works for me just fine, using Spring Security 5.4.1 and Spring Boot 2.4.0
Alternatively, you can add a configuration bean in the context as follows and it will be picked up automatically:
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
   //
}
i

Ivan Pavlov

12/26/2020, 8:08 AM
I'm extending
WebSecurityConfigurerAdapter()
and using spring-security-config 5.4.1. Are you using it the same way?
j

Joris PZ

12/26/2020, 11:45 AM
Yeah, pretty much. This is the essence of my code (although in reality I use the variant with an explicit
@Bean
that exposes a
CorsConfigurationSource
, but this compiles for me)
@Configuration
class APISecurityConfig() : WebSecurityConfigurerAdapter() {

  override fun configure(http: HttpSecurity) {
        http
            .antMatcher("/api/**")
            .cors().configurationSource { CorsConfiguration().applyPermitDefaultValues() }.and()

       // ETC
}
i

Ivan Pavlov

12/26/2020, 11:47 AM
But this is not a dsl, I'm trying to replace this configuration:
http.cors().configurationSource { CorsConfiguration().applyPermitDefaultValues() }
with dsl:
http {
  cors {
    //set configuration source here
  }
}
Sorry if my original question was written badly 🙂
j

Joris PZ

12/26/2020, 11:47 AM
Ah, right! Yeah, then you're on your own 🙂
View count: 9