In kotlin, when I use this way, let bean test2 pass to test3, when I Inject test1, and call test() function, it will get null result when I print test2.
@Service
class Test1(test2: Test2) : Test3(test2) {
@Cacheable(value = ["cacheKey"], key = "#key")
fun cache(key: String): String {
return ""
}
}
@Service
class Test2 {
}
open class Test3(val test2: Test2) {
fun test() {
println(test2)
}
}
but in java, there is no such problem.
@Service
public class JTest1 extends JTest3 {
public JTest1(JTest2 JTest2) {
super(JTest2);
}
@Cacheable(value = "cacheKey", key = "#key")
public String cache(String key) {
return "";
}
}
@Service
public class JTest2 {
}
public class JTest3 {
private final JTest2 JTest2;
public JTest3(JTest2 JTest2) {
this.JTest2 = JTest2;
}
public void test() {
System.out.println(JTest2);
}
}
I decompiled kotlin bytecode, it dose it looks like java class decompiled.
I already figure it out this kotlin issue reason is @Cacheable annotation, it will let spring boot proxy it with cglib.
But I want to known, why only appear in kotlin, what caused the issuse.