Skip to Main Content
Kotlin Cookbook
book

Kotlin Cookbook

by Ken Kousen
November 2019
Intermediate to advanced content levelIntermediate to advanced
254 pages
4h 55m
English
O'Reilly Media, Inc.
Content preview from Kotlin Cookbook

Chapter 12. The Spring Framework

The Spring framework is one of the most popular open source frameworks in the Java world. Spring is all about your project’s infrastructure. You focus on writing beans that contain the business logic you need for your goals, and Spring provides services like security, transactions, resource pooling, and more, based on metadata you provide.

Spring has always been friendly with “alternative” languages on the JVM. Spring has had support for Groovy since at least version 2.5. In the past few versions, the developers of Spring have added capabilities unique to Kotlin as well.

This chapter contains a few select techniques you can use in Spring applications when writing your code in Kotlin. Spring support for Kotlin is still evolving, but this chapter should give you a sense of how Kotlin figures into the Spring ecosystem.

12.1 Opening Spring-Managed Bean Classes for Extension

Problem

Spring needs to generate proxies by extending your classes, but Kotlin classes are closed (final in Java) by default.

Solution

Add the Spring plug-in for Kotlin to your build file, which automatically opens the needed Spring-managed classes for extension.

Discussion

Spring works by providing services to your system. It does so through the Proxy design pattern. The Proxy design pattern, illustrated in UML class and sequence diagrams, is shown in Figure 12-1.

Proxy UML diagram
Figure ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Kotlin

Functional Kotlin

Mario Arias, Rivu Chakraborty
Kotlin Programming Cookbook

Kotlin Programming Cookbook

Aanand Shekhar Roy, Rashi Karanpuria
Functional Programming in Kotlin

Functional Programming in Kotlin

Runar Bjarnason, Paul Chiusano, Marco Vermeulen
Learning Concurrency in Kotlin

Learning Concurrency in Kotlin

Miguel Angel Castiblanco Torres

Publisher Resources

ISBN: 9781492046660Errata PageSupplemental Content