https://kotlinlang.org logo
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
  • r

    rawtoast

    02/26/2018, 5:11 PM
    Hi guys, posted this question about dealing with sealed classes / Json in #jackson-kotlin (not sure if that channel is alive). I would expect someone has dealt with this issue before with Json: https://kotlinlang.slack.com/archives/C0BLHCSHZ/p1519664898000575
    c
    • 2
    • 1
  • s

    sendilkumarn [JHipster]

    02/26/2018, 10:31 PM
    Hey guys, Mixing java + kotlin in a spring boot 2 app along with maven configuration is there any example available? The same app with gradle works fine but not with maven. Any ideas or hints about pom.xml configuration ?
    a
    l
    c
    • 4
    • 26
  • h

    hho

    03/01/2018, 9:52 AM
    Jackson, with the
    @JsonCreator
    annotation
    m
    • 2
    • 1
  • f

    fred.deschenes

    03/01/2018, 3:16 PM
    is there a way to get Spring web to return a 404 if my controller returns an
    Optional
    that is not present?
    c
    r
    • 3
    • 4
  • s

    sendilkumarn [JHipster]

    03/01/2018, 4:22 PM
    what is the advantage of using runApplication instead of springApplication.run()
    s
    • 2
    • 5
  • p

    poohbar

    03/01/2018, 8:12 PM
    I see.. that looks pretty good. Only downside is that it cant be
    val
    . Thanks
    q
    • 2
    • 1
  • s

    sdeleuze

    03/13/2018, 10:04 AM
    https://kotlinlang.slack.com/archives/C19FD9681/p1520935470000483
    n
    • 2
    • 1
  • n

    Nikartix

    03/14/2018, 8:36 AM
    I use spring-boot-2.0.0 with korlin and mongodb, I get this warning every time I start up application,
    org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/libatk-wrapper.so]
    I read it's nothing too serious, application is working fine. But why is it there ? How can I disable this warning ?
    h
    • 2
    • 4
  • p

    poohbar

    03/16/2018, 1:13 PM
    @sdeleuze All my Spring Boot tests are fully written in Kotlin and I am having trouble with context caching. I was wondering how it's supposed to work. I have overall 2 different context (A, B), each has a few tests (denoted by numbers). It runs like this:
    Context A starts
    Test A1 runs
    Test A2 runs
    Context B starts
    Test B1 runs
    Test B2 runs
    Context A starts
    Test A3 runs
    Is this the expected behaviour? I was expecting Spring Boot to "group" the tests by context, but I guess it's just running in whatever order JUnit decided?
    s
    d
    n
    • 4
    • 5
  • b

    bjartek

    03/18/2018, 8:39 PM
    Will do
    c
    • 2
    • 4
  • m

    mp

    03/19/2018, 1:04 PM
    hi there. I have pretty strange question. I think not sure even that it`s possible to solve. I wan't move kafka configuration to the external module and make it reusable with generic(different Pojo in different modules) I'm not sure what subject should I learn about Spring and Kotlin (reflection probably)
    @EnableKafka
    @EnableAsync
    @Configuration
    class KafkaConfig<T>(
            @Autowired val objectMapper: ObjectMapper,
            @Value("\${kafka.bootstrap-servers}") val bootstrapServers: String,
            @Value("\${kafka.consumer.group-id}") val groupId: String,
            @Value("\${kafka.consumer.auto-offset-reset}") val autoOffsetReset: String
    ) {
        @Bean
        fun consumerFactory(): ConsumerFactory<String, T> = DefaultKafkaConsumerFactory(
                consumerConfigs(),
                JsonDeserializer(String::class.java, objectMapper),
                JsonDeserializer(T::class.java, objectMapper)
        )
    
    }
    So issue is - T as non a expression can`t provide ::class.java value Can any one help with documentation topic what I should start from?
    e
    l
    • 3
    • 4
  • g

    goddey

    03/21/2018, 3:25 PM
    Hello. I just noticed my
    BigDecimal
    properties are saved in mongo as
    String
    . Is this a known issue? I didn’t find anything on it when I googled.
    c
    • 2
    • 2
  • m

    m

    03/21/2018, 7:05 PM
    Hi. Is it possible to map request params onto immutable class that has Hibernate Validation annotations (
    @NotNull
    ) ?
    • 1
    • 1
  • m

    Mario Ruiz

    03/28/2018, 3:32 PM
    Hi, I want to use OAuth2, but : - There's 3 kind of auths, a regular user/password, a phone/sms code, and an email/password (each type of auth is for a different user role), so i guess i need 3 different authorizationservers. - I want to configure a prefix for each type - I want to secure my api with them, AND basic I'm using spring boot 2 and spring security, how can i do that?
    c
    • 2
    • 1
  • m

    Michael

    04/03/2018, 4:40 PM
    try
    @field:
    b
    • 2
    • 2
  • p

    poohbar

    04/05/2018, 6:59 PM
    The more I look at it the more I think intelliJ itself should support scanning for
    @ConfigurationProperties
    as part of its Spring support
    y
    • 2
    • 5
  • z

    ziggy42

    04/06/2018, 11:35 AM
    Is there something planned in either Kotlin or Spring to have the issue with default methods in interfaces for
    JpaRepository
    solved?
    g
    • 2
    • 2
  • y

    yaakov

    04/06/2018, 8:05 PM
    Spring Security will provide an automatically generated web form for user credential login... does the form communicate with the server via a RESTful API or...?
    n
    • 2
    • 3
  • s

    sdeleuze

    04/07/2018, 3:24 PM
    What error ?
    m
    • 2
    • 1
  • m

    Michael

    04/09/2018, 9:13 PM
    Trying to upgrade to spring 5/ spring boot 2. I’ve got a``` Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses ... Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses ``` going on.
    c
    • 2
    • 1
  • s

    sdeleuze

    04/10/2018, 10:17 AM
    As documented https://docs.spring.io/spring/docs/current/spring-framework-reference/languages.html#kotlin-requirements 😉
    👍🏼 1
  • l

    Lucas

    04/10/2018, 2:19 PM
    Does someone knows if it's possible to write a DSL to configure the URI of a
    WebTestClient
    instance? For example, instead of writing
    client.get()
            .uri {
                it.path("/get")
                        .queryParam("name", "John Smith")
                        .queryParam("age", 45)
                        .queryParam("isCanadian", true)
                        .build()
            }
            .exchange()
            .expectStatus().isOk
            .expectBody()
            .jsonPath("$.person").exists()
    Write something like
    client.get()
            .uri("/get") {
                +queryParam("name" to "John Smith")
                +queryParam("age" to 45)
                +queryParam("isCanadian" to true)
            }
            .exchange()
            .expectStatus().isOk
            .expectBody()
            .jsonPath("$.person").exists()
    t
    • 2
    • 2
  • j

    Joe

    04/11/2018, 6:18 PM
    not sure if this has been asked/answered already but has anyone encountered and solved the “error” message in Intellij:
    Could not autowire. No beans of '' type found.
    when using DSL bean definition?
    y
    • 2
    • 1
  • m

    mp

    04/11/2018, 9:48 PM
    hi there found funny issue have kotlin config class for kafka
    @Configuration
    class KafkaConfigurator(
            @Value("\${kafka.bootstrap-servers}") val bootstrapServers: String,
            @Value("\${kafka.consumer.group-id}") val groupId: String,
            @Value("\${kafka.consumer.auto-offset-reset}") val autoOffsetReset: String,
            @Autowired val objectMapper: ObjectMapper
    
    ) {
        //bla bla bla, few more beans 
        @Bean
        @Qualifier("producerConfigs")
        fun producerConfigs() = HashMap<String, Any>().apply { //values  }
    
        @Bean
        @Qualifier("consumerConfigs")
        fun consumerConfigs() = HashMap<String, Any>().apply { //values  } 
    }
    and I`m using it in 2 modules: one written on koltin+spring (1.5.12). here injections looks like
    @EnableKafka
    @EnableAsync
    @Configuration
    class KafkaConfig(
            @Autowired val stringJsonMessageConverter: StringJsonMessageConverter,
            @Autowired @Qualifier("producerConfigs") val producerConfigs: Map<String, Any>,
            @Value("\${kafka.topics.companies}") val companiesTopic: String,
            @Value("\${kafka.topics.customers}") val customersTopic: String
    )
    and another written on java+spring (1.5.12). here injections looks like
    public class Application extends ResourceServerConfigurerAdapter {
        @Autowired
        @Qualifier("producerConfigs")
        Map<String, Object> producerConfigs;
    
        @Autowired
        StringJsonMessageConverter messageConverter;
    }
    so issue is that on injection to kotlin module - I have correct map with values that I want to get. But on injection to the java module I got map with key "producerConfigs" and value that contains map that I exactly need. wdyt - should it be reported some were to the spring github or something another?
    • 1
    • 1
  • a

    andyb

    04/15/2018, 10:22 AM
    Can anyone help with a MongoTemplate question? I have got a record structure which has nested arrays and I want to update a specific entry in a 2nd level array. I can find the appropriate entry easier enough by the Set path needs the indexes of both array entries & the '$' only refers to the leaf item. For example if I had an array of teams which contained an array of player I need to generate an update path like :
    val query = Query(Criteria.where("teams.players.playerId").`is`(playerId))
            val update = Update()
            with(update) {
                set("teams.$.players.$.name", player.name)
            ...
    This fails as the '$' can only be used once to refer to the index in the players array, I need a way to generate the equivalent '$' for the index in the teams array. Any ideas for this Mongo newbie?
    :stackoverflow: 2
    c
    • 2
    • 2
  • s

    sdeleuze

    04/17/2018, 1:46 PM
    FYI, I am starting to write 2 new opinionated guides "Building Kotlin applications with Spring Boot and WebFlux" and "Building Kotlin applications with Spring Boot and Spring MVC" because there are too much possible variants and I feel you don't always find the information because it is splitted in too much distinct places (slides, Framework ref doc, Boot ref doc, https://github.com/sdeleuze/ demo projects, Spring blogs, Kotlin Kdoc). There is a need for a pragmatic and canonical place where to find what look like such applications with all best practices. The WebFlux guide will use functional router DSL and handlers. Both will use Junit 5 +
    @Autowired
    injection and show how to do integrations tests and mocked tests.
    ➕ 6
    👍 19
    a
    y
    • 3
    • 7
  • p

    poohbar

    04/18/2018, 4:09 PM
    @mp I guess you do it differently?
    m
    • 2
    • 1
  • m

    mp

    04/18/2018, 4:13 PM
    have u debug it ? add autowire of objectMapper and you will see what kind of mapper u have - 1st rule if you can ask compiler 😁 @poohbar pls continue in thread - we won't be verbose in channel
    p
    • 2
    • 13
  • p

    poohbar

    04/18/2018, 4:50 PM
    So I realized I am not actually getting JSON in the
    @PostMapping
    so it won't use Jackson at all. Can Spring bind form data to Kotlin data class?
    m
    t
    • 3
    • 22
  • v

    visakha

    04/19/2018, 12:59 PM
    @Component
    @ConfigurationProperties()
    class PropHldr {
        companion object {
            @Value("\${sipPropFiles}")
            lateinit var sipPropFile: String
    
        }
    
    
    }
    t
    c
    • 3
    • 9
Powered by Linen
Title
v

visakha

04/19/2018, 12:59 PM
@Component
@ConfigurationProperties()
class PropHldr {
    companion object {
        @Value("\${sipPropFiles}")
        lateinit var sipPropFile: String

    }


}
t

tginiotis

04/19/2018, 1:08 PM
since the companion object is essentially a singleton object created outside of the spring context - autowiring for it needs to be called manually. You can grab a
AutowireCapableBeanFactory
from somewhere, e.g. by dependency injection or during
SpringApplication
setup and call
beanFactoryInstance.autowireBean(PropHldr.Companion)
v

visakha

04/19/2018, 1:23 PM
Thank you, may be Companion Object is a wrong idea... all I wanted to do is
@Value("\${sipPropFile}")
read from the application.properties file..... the below is also not working
@Configuration()

class Routing {

    @Value("\${sip.sipPropFile}")
    lateinit var sipPropFile: String
c

Czar

04/19/2018, 1:27 PM
Also, for multi-line chunks of code you can use triple backticks 🙂
v

visakha

04/19/2018, 1:29 PM
yep, thx
t

tginiotis

04/19/2018, 1:32 PM
I think you have to define the path to the properties file for this to work. You can find an example in https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html, under the
Using the @Value annotation
heading
v

visakha

04/19/2018, 1:55 PM
@PropertySource("classpath:application.properties")
did the trick 🙂
👍 1
@Tadas Giniotis the link you sent me helped
its a wonder when Spring Boot says -- its convention based and still makes you specify the properties file explicitly for the
@Configuration
annotation -- btw I was running the JUnit5 test case, this is where it originated
t

tginiotis

04/19/2018, 2:01 PM
judging from this it should work without explicitly specifying the path - https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
View count: 12