Spring Config and missing Kotlin members
Kotlin is now a first-class citizen in the Spring Framework, and in IntelliJ IDEA we are trying to make all the Spring features that have worked with Java over the years work with Kotlin too. In this series of blog posts, we will walk you through some of these features using Kotlin samples, this will also be a reminder in case you missed them for Java.
And today we’ll start with XML-configuration config support. XML-based Spring configurations are not so popular nowadays, but a large number of our users still use them, and IntelliJ IDEA can help maintain such configurations.
For instance, by having a simple Kotlin class:
package org.jetbrains.samples.kotlinspring class KtBean
we can start using it in a Spring. XML file:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="bean" class="org.jetbrains.samples.kotlinspring.KtBean"/> </beans>
And then if you realize that you want to add an initialization method. Then you could just write it in the XML config and use a quick-fix to add it to the Kotlin class:
Of course, you’ll still get all the navigation and completion features
It also works in a similar way with code-based configurations:
And in the same way it works with constructors: if you need a constructor for a bean, IntelliJ IDEA will also add them (or modify the existing one):
If you need a property in the Kotlin class this quick-fix will suggest creating a `lateinit var` that allows you to have uninitialized non-nullable properties, which is very handy for Spring beans:
So if you use some non-existing members of a class in Spring-configuration – IntelliJ IDEA will help you add these members to the class, even if your class happens to be in Kotlin.
Subscribe to Blog updates
Thanks, we've got you!
The What, Why, and How of JPA Buddy in IntelliJ IDEA
Master JPA entity management with JPA Buddy in IntelliJ IDEA! Our latest article shows you how to simplify your workflow and reduce boilerplate code.
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Import Postman Collections to the HTTP Client
We know that many of you use Postman collections and want to stay in the flow while working with them. This means staying inside IntelliJ IDEA and not switching to a different app. Great news! You can now effortlessly transform Postman collections into .http and use them in the HTTP Client …
Profile on the Fly With the IntelliJ Profiler
At JetBrains, we believe that profiling should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission. In previous releases, we introduced a range of features to s…