Skip to content

Commit 0de3b30

Browse files
committed
Provide guidelines for using Kotlin properties with proxies
A typical use case is `@Scope` and its popular `@RequestScope` specialization. Closes gh-32287
1 parent 45c2104 commit 0de3b30

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

framework-docs/modules/ROOT/pages/languages/kotlin/spring-projects-in.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ in Kotlin.
99
[[final-by-default]]
1010
== Final by Default
1111

12-
By default, https://discuss.kotlinlang.org/t/classes-final-by-default/166[all classes in Kotlin are `final`].
12+
By default, https://discuss.kotlinlang.org/t/classes-final-by-default/166[all classes and member functions in Kotlin are `final`].
1313
The `open` modifier on a class is the opposite of Java's `final`: It allows others to inherit from this
1414
class. This also applies to member functions, in that they need to be marked as `open` to be overridden.
1515

@@ -38,6 +38,12 @@ Meta-annotation support means that types annotated with `@Configuration`, `@Cont
3838
`@RestController`, `@Service`, or `@Repository` are automatically opened since these
3939
annotations are meta-annotated with `@Component`.
4040

41+
WARNING: Some use cases involving proxies and automatic generation of final methods by the Kotlin compiler require extra
42+
care. For example, a Kotlin class with properties will generate related `final` getters and setters. In order
43+
to be able to proxy related methods, a type level `@Component` annotation should be preferred to method level `@Bean` in
44+
order to have those methods opened by the `kotlin-spring` plugin. A typical use case is `@Scope` and its popular
45+
`@RequestScope` specialization.
46+
4147
https://start.spring.io/#!language=kotlin&type=gradle-project[start.spring.io] enables
4248
the `kotlin-spring` plugin by default. So, in practice, you can write your Kotlin beans
4349
without any additional `open` keyword, as in Java.

0 commit comments

Comments
 (0)