Description
Placeholder issue for things we can do to improve Kotlin support
@value
Using @Value("${thing}")
is a pain because you need to escape $
(e.g. @Value("\${thing}")
. Perhaps a different key like @Value("#{thing}")
.
Open Classes
Open classes are a pain, can we use a classloader to remove final
.
Also all @Bean
methods
perhaps we can use a custom bean classloader
Default constructor arguments with @Autowired
Give a constructor with a default param:
open class Foo @Autowired constructor(val restTemplate: RestOperation = NoOpRestOperation());
Kotlin will create multiple constructors, this makes Spring fall over because there's multiple annotated constructors. A method to be smart about which to pick would be nice.
Main method
@JvmStatic
is needed for main methods. Check if we can find them automatically. Also the name of the class is a bit mad ThePackageKt
so perhaps we can replace it with something nice.
Add Kotlin Module
Look at Jackson for an example.
Activity
wilkinsona commentedon Mar 31, 2016
Gradle plugin
Our plugin applies the Java plugin automatically. That doesn't make sense when you're building a pure Kotlin project and leads to unnecessary noise as the Java-related tasks are still run as part of the build:
philwebb commentedon Mar 31, 2016
/cc @jkschneider
philwebb commentedon Mar 31, 2016
If looks like
@Value
might already support#{...}
expressions as an alternative to${...}
.jkschneider commentedon Apr 2, 2016
Spring MVC
Reified extension functions for the
RestOperations
interface. There are probably similar better-typing gains to be made elsewhere.jkschneider commentedon Apr 2, 2016
Spring HATEOAS
Extension functions to improve the transformation of objects and collections of objects into
Resource
andPagedResources
, respectively. Also better link generation forResource
andPagedResources
.sdeleuze commentedon Apr 2, 2016
Thanks for creating this issue @philwebb 👍, I am especially interested by removing the need for the
open
qualifier.Maybe we could discuss Monday with the team if they would be ok to automatically register Kotlin Jackson module in
Jackson2ObjectMapperBuilder
if it is in the classpath like we do for various other modules (I could add this to Spring Framework 4.3 easily).@jkschneider Good idea about Spring HATEOAS. Be aware that I also plan to experiment on allowing to specify relations thanks to annotations + regular data classes, see spring-projects/spring-hateoas#401 for more details. Nothing specific to Kotlin, but that will make it easier to deal with data classes in both Kotlin and Java.
sdeleuze commentedon Apr 4, 2016
@philwebb SPR-14108 + related pull request for Jackson Kotlin module automatic registration submitted for inclusion in Spring Framework 4.3.
sdeleuze commentedon Apr 4, 2016
I have just merged Jackson Kotlin module automatic registration, so it will be available in
4.3.0.RC1
upcoming release tomorrow and then in Spring Boot1.4
.About
@Value
I did a quick test some times ago, and I dont remember#
was supported out of the box as a dropin replacement for$
, I think only@Value("#{config['foo']})
and@Value("\${foo}")
were. That's why I described in this StackOverflow answer how to customize${...}
to something else. Is there a better solution available out of the box?About extensions, Kotlin Primavera contains some examples of Kotlin extensions applied to Spring (I am sure there a lot of others to imagine even more useful).
I have tried to reproduce the "Default constructor arguments with
@Autowired
" described above in this test project but did not succeed. Any chance someone send a PR on this test project to show how to reproduce this issue?You can find bellow some issues from Kotlin bugtracker related to Spring:
AnnotationConfigApplicationContext()
call are not resolvedjkschneider commentedon Apr 4, 2016
@lkogler - Hadi Hariri mentioned you as a Spek contributor. Thought you might be interested in this effort as well.
jkschneider commentedon Apr 4, 2016
@sdeleuze Sent a PR for "Default constructor arguments with
@Autowired
". Addingrequired=false
was a valid workaround as of some pre-1.0 release, but no longer works.Thanks for putting together all of the links!
@philwebb or @sdeleuze if you could create a spring-kotlin project in spring-projects and give me commit access, I'll start pouring in the work I have here.
sdeleuze commentedon Apr 4, 2016
@jkschneider As a first step I have created the
spring-kotlin
in my ownsdeleuze
account. Maybe we could both of us (and any interested people) contribute anything useful for building Spring + Kotlin applications, including documentation. When the project will be mature enough, we will evaluate moving it to https://github.com/spring-projects.I already gave you the push rights, please sign the CLA as explained in the README. I will setup the build process using http://build.spring.io and publish the snapshots in https://repo.spring.io/snapshot/ as soon as we have the first bits committed.
Does it sound ok for you?
spencergibb commentedon Apr 4, 2016
@sdeleuze He's signed the CLA for spring cloud previously.
jkschneider commentedon Apr 4, 2016
@sdeleuze thanks, sounds like a plan!
nfrankel commentedon Apr 4, 2016
I'm interested as well, and have just signed (again?) the CLA - just to be sure.
37 remaining items