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
  • l

    Leon

    11/17/2019, 8:43 PM
    This might help: https://spring.io/guides/tutorials/spring-boot-kotlin/ see the UserController class
    h
    n
    +4
    • 7
    • 14
  • j

    jbnizet

    11/17/2019, 11:25 PM
    I would strongly advise against that. It does things in a way that goes against the philosophy of Spring, and DI in general. And it makes the code impossible to test. Say you create a mock repository and inject it into a service that you want to unit-test. The save() method of the user will not use the mocked repository. It will try to access a global USER_REPOSITORY variable, which might or might not be initialized depending on which tests have been run before. DI is your friend. It’s used for good reasons.
    🇳🇴 2
    👍🏾 1
    j
    k
    +4
    • 7
    • 15
  • j

    jubril

    11/18/2019, 10:31 AM
    Can someone point me to an article/anything that could help understand the bare of spring?
    m
    l
    • 3
    • 2
  • h

    Hullaballoonatic

    11/18/2019, 5:43 PM
    I end up writing a lot of
    @Bean
    fun springClassInstance() = SpringClass().apply {
        setA(a)
        setB(b)
        setC(c)
    }
    this syntax just makes me cry. it's a shame there can't be more constructor variants or at the very least builders for some of these classes... it would be so much nicer to just be
    @Bean fun springClassInstance() = SpringClass(a = a, b = b, c = c)
    but you know.... java things. nvm me, complaining to the ether
    t
    m
    • 3
    • 7
  • h

    Hullaballoonatic

    11/18/2019, 7:01 PM
    Is there a way to add methods to Repository interfaces that are not intended as queries? e.g.
    interface Repository<E : MyEntity> : JpaRepository<E, String> {
        operator fun contains(id: String) = existsById(id)
    
        operator fun get(id: String) = findByIdOrNull(id)
    }
    I'm exploring the possibility of having route controllers talk directly to repos, but a service in the middle to transform dao and dto is probably still too useful to warrant that
    s
    k
    • 3
    • 4
  • p

    pavel

    11/21/2019, 10:06 PM
    I don’t think you can combine an update with an inner join
    t
    • 2
    • 1
  • s

    sdeleuze

    11/22/2019, 2:16 PM
    I intend to make Spring DSL class (like
    RouterFunctionDsl
    ) constructors internal via
    internal constructor
    since they are intended to be used only via builder functions like
    router { }
    ,
    bean { }
    or extensions like
    mockMvc.get()
    . Any objection?
    👍 11
    n
    • 2
    • 1
  • a

    aaverin

    11/26/2019, 10:45 AM
    Anybody already tried using
    kotlinx.serialization
    with SpringBoot? Or it’s not a good idea to explore this?
    p
    b
    • 3
    • 4
  • e

    EricJTurley

    11/26/2019, 7:50 PM
    I tried using
    @ConstructorBinding
    @ConfigurationProperties("push")
    data class PushServicesProperties(val snsClient: SnsClient) {
    
        data class SnsClient(
            val maxConnections: Int,
            val connectionTimeout: Int,
            val socketTimeout: Int,
            val proxyHost: String,
            val proxyPort: Int
        )
    }
    But I'm still getting
    No default constructor found
    for the
    PushServiceProperties
    class. Has anyone else had that problem? Everything looks normal...
    e
    e
    +2
    • 5
    • 17
  • a

    Alex Ku3menk0

    11/28/2019, 11:45 AM
    Hi guys! I'm struggling with testing Controllers based on WebFlux. I'm getting an error:
    No qualifying bean of type 'kotlin.coroutines.CoroutineContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    My controller looks like:
    @Controller
    class MobileController {
    
      @PostMapping("/register")
      suspend fun register() {
        ...
      }
    }
    and my test:
    @WebFluxTest(MobileController::class)
    internal class MobileControllerTest {
    
        @Autowired
        lateinit var client: WebTestClient
    
        @Test
        fun handleRegister() = kotlinx.coroutines.runBlocking {
            <http://client.post|client.post>()
                    .uri("/register")
                    .exchange()
                    .expectStatus().isOk
        }
    }
    Does anyone know how to fix it? Thanks in advance 🙂
    g
    • 2
    • 1
  • l

    Lukasz Mlynik

    12/01/2019, 5:34 PM
    Hey, I was looking around here, documentation and checked how does openapi-generator does it - and still everywhere the DTOs for Spring are using nullable fields with defaults, is there a better way to make json handle data classes? openapi does it like this
    data class Pet (
    
            @get:NotNull 
            @JsonProperty("name") val name: kotlin.String,
    
            @get:NotNull 
            @JsonProperty("photoUrls") val photoUrls: kotlin.collections.List<kotlin.String>,
    
            @JsonProperty("id") val id: kotlin.Long? = null,
    
            @JsonProperty("category") val category: Category? = null,
    
            @JsonProperty("tags") val tags: kotlin.collections.List<Tag>? = null,
    
            @JsonProperty("status") val status: Pet.Status? = null
    )
    m
    • 2
    • 1
  • t

    tiare.balbi

    12/03/2019, 5:31 AM
    Has anyone come across of this error? Using data class with Spring Data Rest. The
    kotlin('plugin.allopen')
    was added to the gradle.
    @Component
    class UserRestConfigurer : RepositoryRestConfigurer {
    
        override fun configureRepositoryRestConfiguration(config: RepositoryRestConfiguration) {
            config.withEntityLookup()
                .forRepository<User, Long, UserRepository>(UserRepository::class.java)
                .withIdMapping(User::email)
                .withLookup(UserRepository::findByEmail)
        }
    }
    a
    • 2
    • 1
  • c

    Czar

    12/03/2019, 2:11 PM
    Hi, I remember watching some video where speaker was talking about changes in Spring 5.Some.Version. There was something about difference between
    @Configuration class MyConf(private val someBean: SomeBean) {
        @Bean fun myBean(): MyBean { /* do something with someBean */ }
    }
    and
    @Configuration class MyConf {
        @Bean fun myBean(someBean: SomeBean): MyBean { /* do something with someBean */ }
    }
    But I don't remember either which video it was or what was the difference. Googling around didn't yield any results yet. Does anyone remember/know what I'm talking about?
    🤔 1
    c
    • 2
    • 7
  • b

    bjonnh

    12/04/2019, 9:30 PM
    How hard is it to write a new provider for spring data? (to support a new database)
    c
    • 2
    • 3
  • c

    cpe

    12/06/2019, 10:29 AM
    Is there an equivalent for @ControllerAdvice when using the new functional API in WebMVC? I'd like to put some generic information (like user, menu etc.) into the model but don't want to always call a function like "baseModel(...)". I'm also open for other ideas 🙂
    n
    • 2
    • 1
  • y

    Yousef

    12/06/2019, 5:18 PM
    Hey, so I'm making a call to spring boot from android and it returns code 500, no message or anything and spring doesn't show the error. How do I go about finding out what the issue is?
    g
    • 2
    • 1
  • r

    Robert Jaros

    12/08/2019, 11:24 AM
    In 2.2.2 release of Spring Boot, Kotlin was updated to 1.3.60, but coroutines version was not updated to 1.3.2-1.3.60. Is this a mistake or intentional?
    e
    • 2
    • 6
  • r

    Roy Nard

    12/09/2019, 2:43 PM
    So why are not all endpoints non-blocking.. Or are they? I am thinking of co-routines and that one needs to use WebFlux/Netty in order to achieve this. In Python, async is build into the language interpreter, not spawning any new threads. I am talking about aiohttp in this case. In "Normal Java" one would go about and spawn threads a few years ago. but today, in kotlin and spring, why arent all endpoints non-blocking by default,? Or are we heading there - are we just interim these two paradigms.
    a
    • 2
    • 14
  • p

    pdegand

    12/09/2019, 2:55 PM
    Hello, with my team we want to make a progressive transition to webflux. But we would like to use the coroutine support of webflux instead of Mono/Flux. I’ve seen in the presentation from Sébastien at KotlinConf that the support for coroutine in WebMVC controllers are not available yet. I’m wondering if it’s a good alternative to begin refactoring the app to have a big
    runBlocking { }
    inside the WebMVC controller until all of the controller are refactored, and when we are ready, to remove the dependency to webmvc to enable the full reactive stack, remove all the
    runBlocking
    and convert the controller methods to
    suspend
    ?
    s
    a
    • 3
    • 12
  • c

    Czar

    12/12/2019, 1:20 PM
    with latest spring boot and kotlin I'd like to have something like this:
    @Component class MyComponent(...) {
      fun someFun() {
        /* do something non-transactional before the transaction */
        inTransaction(txType = TxType.REQUIRED, readOnly = false) {
          /* do something inside a transaction */
        }
        /* do something non-transactional after the transaction */
      }
    }
    What would be the best way to implement the
    inTransaction
    fun?
    t
    d
    j
    • 4
    • 14
  • t

    tjb

    12/18/2019, 5:18 PM
    hey everyone i have a quick question: since the authorization server for oauth2 is deprecated now, what is the preferred method to have oauth2 in spring going forward?
    m
    a
    b
    • 4
    • 7
  • d

    Dave Jensen

    12/18/2019, 7:16 PM
    I am using a
    data class
    for the Entity but, unless I'm missing something, I'm not sure that should matter. Has anybody successfully used a delegate in their entities?
    t
    b
    • 3
    • 9
  • k

    Karolis

    01/06/2020, 8:54 AM
    I want to add annotations on my package. I can do so with adding
    package-info.java
    file near my Kotlin code. It works while I run my app from IDE, but if I package app as a fat jar (
    gradle bootJar
    ), it stops working. The only fix I came across is to place the package-info in
    src/java
    instead of
    src/kotlin
    . Is there a way to instruct gradle to include package-info.java to resulting spring boot jar?
    m
    • 2
    • 4
  • n

    Naveenkumar R

    01/06/2020, 2:08 PM
    Hi All @here, I'm an android dev, I have planned to start back-end now. I know the basics in java servlets. I have planned to start spring frame work. Please help me to start.
    e
    c
    • 3
    • 2
  • b

    bjonnh

    01/10/2020, 5:17 PM
    How do you handle that they both want to control the app lifecycle
    • 1
    • 3
  • e

    EarthCitizen

    01/13/2020, 5:10 PM
    When writing Spring REST services in Kotlin, would controller functions be a typical and safe place to call
    runBlocking { }
    ?
    d
    • 2
    • 10
  • d

    Dariusz Kuc

    01/13/2020, 5:40 PM
    hello, any idea how to verify JSON response from WebTestClient to check if fields are null? e.g.
    testClient.get()
        .uri("whatever")
        .accept(APPLICATION_JSON)
        .exchange()
        .expectStatus().isOk
        .expectBody()
        .jsonPath("$.whatever").isEqualTo(null) // NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
    If I enable
    jsr305=strict
    compiler settings the above fails complaining it expects non-null
    Any
    b
    • 2
    • 9
  • b

    bjonnh

    01/15/2020, 5:32 PM
    got my spring+jfx prototype working
    t
    r
    • 3
    • 9
  • s

    Sindy Senorita

    01/16/2020, 12:17 AM
    Hi, I’m trying to build a multi-module, aggregation type, spring boot project (like in https://www.baeldung.com/spring-boot-multiple-modules) I got a root pom.xml that specifies 2 modules: 1 app module and 1 library module when I run
    mvn clean package
    , the library module compiles successfully but the application module does not find the library module with error
    Unresolved reference: thelibrarymodule
    This sounds like a classic spring boot problem, but no post in internet seem to have proper fix/explanation. This is driving me insane Can someone please help me? any explanation of the root cause or any suggested keyword to google with? Thanks in advance
    c
    • 2
    • 1
  • v

    viralshah

    01/19/2020, 3:38 PM
    Hi guys, I am new and starting out with Coroutines and Spring integration. Now that Spring Boot 2.2 are released, is there a comprehensive example where a basic crud app is using coroutines (I guess probably with R2DBC)? I want to learn how and where to spawn coroutines and know when to use the right context. Thanks
    r
    e
    r
    • 4
    • 6
Powered by Linen
Title
v

viralshah

01/19/2020, 3:38 PM
Hi guys, I am new and starting out with Coroutines and Spring integration. Now that Spring Boot 2.2 are released, is there a comprehensive example where a basic crud app is using coroutines (I guess probably with R2DBC)? I want to learn how and where to spawn coroutines and know when to use the right context. Thanks
r

Rodrigo Silva

01/19/2020, 9:03 PM
I think the best way to use coroutines is with Ktor. But, if you want to use it with Spring, maybe, the you should use it with webFlux. Here an exemple: https://github.com/sdeleuze/spring-boot-coroutines-demo
💯 1
v

viralshah

01/20/2020, 2:06 AM
thanks, will for sure take a look. I am considering moving to Ktor, but I still need to get more developer buy in. Out of curiosity, is there anything major in Spring, that Ktor can not do?
e

Evgeniy Zaharov

01/20/2020, 8:29 AM
ktor doesn’t have inner DI, so all magic with spring-starters is not possible to do with ktor. You can add DI by youself to ktor, but it’s not be such powerfull as in spring
☝️ 3
r

Rodrigo Silva

01/20/2020, 12:24 PM
Well, Spring its a exclente tool, the most used with java. But i don't like it, becouse have a lot of "magic" behind it, with all annotations. I use it when the customers ask. Otherwised i prefer Ktor. I think all the things that Spring does, Ktor can also do, but with different implementation.
e

Evgeniy Zaharov

01/20/2020, 12:53 PM
In a spring it’s possible to add one starter with some db, and it checks, whatever you have already configure DB connection, or not, and if you have it, starter will use this connection (and ever more of this, in starter possible to check if class exists and make add configuration depend on it). In ktor you need to do all this by yourself. This is just one of simplest example. I like ktor, it’s very good designed library, and well suited for many projects. But for big project Spring is still more preferred.
r

Razvan

01/20/2020, 2:16 PM
Your can also find an exemple here: https://github.com/razvn/webflux-r2dbc-kotlin
💯 1
View count: 5