Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A team wants to write new Spring Boot services in Kotlin while the rest of the organisation uses Java. What technical issues should they plan for?

The team should plan for five things: Kotlin's null safety does not cover Java code unless that code carries nullability annotations; Spring needs open classes for proxies, which the kotlin-spring compiler plugin handles; JPA entities need no-arg constructors and non-final classes, handled by the kotlin-jpa plugin plus all-open for entities; coroutines are a different concurrency model from virtual threads and mixing both needs care; and build times and tooling differ, which affects shared libraries and CI.

Why this question is asked

Kotlin works well with Spring Boot, and the Spring team supports it officially, so writing new services in Kotlin is a reasonable choice. But a few problems only appear once a Kotlin service meets Spring's proxies, JPA's entity rules and the organisation's Java libraries, and they tend to show up as confusing runtime errors rather than compile errors. Interviewers ask this scenario to see whether we know where Kotlin and the Java ecosystem rub against each other. In this answer, we will go through null safety at the Java boundary, the compiler plugins Spring and JPA need, the concurrency model choice, and the build and library concerns.

1A Quick Recap: Kotlin on a Java Platform

Kotlin compiles to the same bytecode as Java and can use any Java library, which is why Spring, Hibernate and Jackson work with it. But Kotlin makes different default choices from Java. Classes and methods are final unless marked open. Types are non-null unless marked with a question mark, as in String? for a string that may be null. And Kotlin offers its own concurrency model, coroutines. Each of these defaults meets a Java framework that assumes something else, and each section below is one of those meetings.

2Null Safety Stops at the Java Boundary

Inside Kotlin code, the compiler guarantees that a String is never null. But when Kotlin calls a Java method, it does not know whether the result can be null unless the Java code says so with annotations. Without them, Kotlin treats the result as a platform type, written String! in error messages, which means it trusts us to decide. If we decide wrongly, we get a NullPointerException at run time, just as in Java.

Java
// Java library, no annotations
public class CustomerClient { public String findEmail(long id) { return null; } }
// Kotlin service
val email: String = client.findEmail(42) // compiles: platform type String! treated as String
// -> java.lang.NullPointerException at run time: findEmail(...) must not be null
val safe: String? = client.findEmail(42) // correct: we admit it may be null
println(safe ?: "no email") // no email

The fix is on both sides. In Kotlin, we treat results from unannotated Java code as nullable. In the shared Java libraries, we add nullability annotations. Spring Framework 7 and Spring Boot 4 annotate their APIs with JSpecify annotations such as @Nullable and @NullMarked, which Kotlin understands, so Spring's own APIs come through with proper nullable and non-null types; our internal Java libraries should do the same. Check your versions, as earlier Spring releases used Spring's own annotations.

3Spring Needs Open Classes for Proxies

Spring adds features such as @Transactional, @Cacheable and @Async by creating a proxy: a subclass generated at run time that wraps our bean and adds the behaviour before and after each call. Configuration classes annotated with @Configuration are proxied the same way. A subclass can only override methods that are not final, and in Kotlin everything is final by default. Without help, Spring either fails at startup with an error that the class cannot be subclassed, or, worse, the annotation silently does nothing for a final method.

The kotlin-spring compiler plugin solves this. It is a preset of the all-open plugin that makes classes open automatically when they carry Spring annotations such as @Component, @Service, @Transactional, @Async, @Cacheable and @SpringBootTest, including meta-annotations. Spring Initializr adds it to every new Kotlin project, and we should make sure it is in our standard build too.

Java
// build.gradle.kts
plugins {
kotlin("jvm") version "2.2.0" // check the version your Spring Boot release supports
kotlin("plugin.spring") version "2.2.0" // all-open for Spring-annotated classes
kotlin("plugin.jpa") version "2.2.0" // no-arg constructors for JPA entities
}
allOpen {
annotation("jakarta.persistence.Entity") // entities open too, for lazy-loading proxies
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
}

4JPA Entities Need No-Arg Constructors and Open Classes

JPA, the Java persistence standard that Hibernate implements, creates entity objects by calling a no-arg constructor and then setting fields, and it creates lazy-loading proxies by subclassing entities. A typical Kotlin class has only a primary constructor with parameters and is final, so neither works.

The kotlin-jpa plugin generates a synthetic no-arg constructor for classes annotated with @Entity, @Embeddable and @MappedSuperclass, usable by Hibernate but not by our code. It does not make them open, which is why we add the entity annotations to all-open as shown above. We also avoid data classes for entities: their generated equals and hashCode use every property, including lazy associations and a generated id that changes on save, which breaks sets and triggers unwanted loading. A plain class with equals based on the id, written carefully, is safer.

Where Kotlin defaults meet Spring and JPA
Kotlin defaultFramework expectsFix
types non-nullJava APIs may return nullnullability annotations, String? at the boundary
classes finalSpring proxies subclass beanskotlin-spring (all-open preset)
no no-arg constructorJPA instantiates entitieskotlin-jpa (no-arg)
entity classes finalHibernate lazy proxiesall-open for @Entity
data class equalsstable entity identityplain class, id-based equals

5Coroutines or Virtual Threads?

Kotlin coroutines are lightweight tasks managed by Kotlin's runtime. A suspend function can pause at a call such as a network request without blocking a thread, and Spring supports suspend functions in controllers, especially with WebFlux. Java 21 added virtual threads, which give similar scalability with plain blocking code, and Spring Boot turns them on with spring.threads.virtual.enabled=true.

Both are fine, but the team should pick one model per service. Mixing them means two ways of propagating context such as security and tracing, two ways of cancelling work, and confusing interactions, such as blocking calls inside coroutines that occupy dispatcher threads. For a team coming from Spring MVC and blocking JDBC, virtual threads with ordinary Kotlin code are usually the simpler path; coroutines pay off with reactive stacks or when the team wants structured concurrency features such as scoped cancellation.

6Build Times, Tooling and Shared Libraries

The Kotlin compiler is slower than javac, and mixed Java and Kotlin modules compile in two passes, so CI times grow; Gradle's build cache and incremental compilation help. Annotation processing in Kotlin uses kapt or the faster KSP, and not every Java annotation processor supports KSP, so check the ones the team uses, such as MapStruct. Static analysis, code coverage and formatting tools differ, so CI needs Kotlin equivalents such as detekt and ktlint.

The biggest organisational issue is shared libraries. Kotlin services can consume Java libraries easily. The reverse is harder: a shared library written in Kotlin brings the Kotlin standard library as a dependency to Java services and exposes Kotlin-isms to Java callers. So the rule should be that shared libraries stay in Java, ideally with nullability annotations, and Kotlin is used inside services.

7Follow-up questions

Will Jackson work with Kotlin data classes as request bodies?

Yes, with the jackson-module-kotlin dependency, which teaches Jackson to use Kotlin constructors, default values and nullability. Spring Boot registers the module automatically when it is on the class path. Without it, deserialization of classes without a no-arg constructor fails.

What happens if someone forgets the kotlin-spring plugin?

Spring cannot subclass final classes, so a @Configuration class fails at startup, and for other beans the outcome depends on the proxy type: some fail to start, and some final methods run without the proxy's behaviour, so a @Transactional method silently runs without a transaction. Making the plugin part of the standard build template prevents this.

Should the team write tests in Kotlin too?

Yes, usually; tests in the same language as the code keep things simple, and libraries such as MockK fit Kotlin's final classes better than Mockito's defaults. Spring Boot's test support works the same in Kotlin.

8Conclusion

In this answer, we saw the technical issues of writing Spring Boot services in Kotlin: null safety that stops at unannotated Java code, Spring proxies that need open classes from the kotlin-spring plugin, JPA entities that need no-arg constructors and all-open, the choice between coroutines and virtual threads, and build and tooling differences that affect CI and argue for keeping shared libraries in Java.

What to say in the interviewAbout 80 seconds aloud

Open with

Kotlin works well with Spring, but there are five things I would plan for. First, null safety stops at the Java boundary: if a Java library has no nullability annotations, Kotlin sees platform types and we can still get NullPointerExceptions, so we treat those results as nullable and annotate our shared Java libraries; Spring Framework 7 uses JSpecify annotations, which Kotlin understands.

Then, if they want more

Second, Kotlin classes are final by default, but Spring creates proxies by subclassing for @Transactional, @Cacheable and @Configuration, so we need the kotlin-spring plugin, otherwise startup fails or annotations silently do nothing.

Third, JPA needs no-arg constructors and Hibernate's lazy proxies need non-final classes, so we add the kotlin-jpa plugin plus all-open for @Entity, and avoid data classes as entities because their equals and hashCode cause trouble.

Fourth, concurrency: coroutines and virtual threads both scale, but I would choose one per service, probably virtual threads for a blocking MVC and JDBC stack, to avoid two models for context and cancellation. Fifth, build and tooling: Kotlin compiles slower, annotation processors need kapt or KSP, and we need Kotlin linters in CI.

I would also keep shared libraries in Java so Java services do not inherit the Kotlin standard library and Kotlin-specific APIs.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Spring Boot 4, Spring Framework 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A team wants to write new Spring Boot services in Kotlin while the rest of the...": https://scrivio-interview-library.netlify.app/java/jvm-architecture/c3043ff606/