Hi, I just upgraded from Spring Boot 1.5.9 to 2.0...
# spring
o
Hi, I just upgraded from Spring Boot 1.5.9 to 2.0.2 and Spring can no longer create instances of my private components. The following worked in 1.5.9:
Copy code
@Component
private class ActivityRepositoryImpl(private val dbCursor: DbCursor) {
	...
}
After upgrading Spring greets me with the following stacktrace:
Copy code
Caused by: java.lang.IllegalAccessException: Class kotlin.reflect.jvm.internal.FunctionCaller$Constructor can not access a member of class com.trireduce.persistence.ActivityRepositoryImpl with modifiers "public"
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) ~[?:1.8.0_112]
        at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) ~[?:1.8.0_112]
        at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) ~[?:1.8.0_112]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:413) ~[?:1.8.0_112]
        at kotlin.reflect.jvm.internal.FunctionCaller$Constructor.call(FunctionCaller.kt:66) ~[kotlin-reflect-1.2.41.jar:1.2.41-release-74 (1.2.41)]
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:107) ~[kotlin-reflect-1.2.41.jar:1.2.41-release-74 (1.2.41)]
        at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod(KCallableImpl.kt:149) ~[kotlin-reflect-1.2.41.jar:1.2.41-release-74 (1.2.41)]
        at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:111) ~[kotlin-reflect-1.2.41.jar:1.2.41-release-74 (1.2.41)]
        at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:765) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
        ... 22 more
Does anybody have an idea how to solve this?
m
why something with @component is
private
? I assume that
private
access modifier is issue. but don't know how to explain that it works on 1.5 and on 2.0 doesn't
o
Yeah, the issue is solved by removing the `private`modifier. We would however like to keep the implementations hidden and only keep the interfaces public.
c
use
internal
and keep interfaces and implementations in separate packages/modules
👍 1
o
Yeah, thats definitely another solution. Will probably be good enough. What bothers me a bit is that things worked fine in 1.5.9 and not in 2.0.2. I created a small demo-project that shows the error: https://github.com/owyke/spring-private-components
Thanks for the proposed solutions though ❤️