New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating bean after Spring Boot upgrade 1.3.6 -> 1.4.0 #6526

Closed
mgorniew opened this Issue Aug 1, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@mgorniew

mgorniew commented Aug 1, 2016

Hi,

I've changed spring boot version from 1.3.6 to 1.4.0 in my project. Now, during application start, I'm getting cglib error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataController': Unsatisfied dependency expressed through field 'dataService': Error creating bean with name 'inMemoryRealTimeDataService': Unsatisfied dependency expressed through field 'dataProcessorProvider': Error creating bean with name 'realTimeDataProcessorProvider': Unsatisfied dependency expressed through field 'configurationService': Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'realTimeDataProcessorProvider': Unsatisfied dependency expressed through field 'configurationService': Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryRealTimeDataService': Unsatisfied dependency expressed through field 'dataProcessorProvider': Error creating bean with name 'realTimeDataProcessorProvider': Unsatisfied dependency expressed through field 'configurationService': Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'realTimeDataProcessorProvider': Unsatisfied dependency expressed through field 'configurationService': Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultInstrumentConfigurationService' defined in URL [jar:file:/C:/work/ABB/leak_detection_v2/backend/instrument/data/config/build/libs/instrument-data-config-2.0.0-SNAPSHOT.jar!/com/lgr/leak/instrument/data/config/impl/DefaultInstrumentConfigurationService.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService]: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
....
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:413)
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336)
    ... 80 common frames omitted
Caused by: java.lang.IllegalAccessError: class com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService$$EnhancerBySpringCGLIB$$2753248a cannot access its superclass com.lgr.leak.instrument.data.config.impl.DefaultInstrumentConfigurationService
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    ... 85 common frames omitted

DefaultInstrumentConfigurationService is package private class:

@Service
@Slf4j
class DefaultInstrumentConfigurationService implements InstrumentConfigurationService {
...

    DefaultInstrumentConfigurationService() {
        this.columnGenerator = new DefaultColumnGenerator();
    }

...
}

But this worked fine in spring boot 1.3.6.

Thanks,
Michał

@wilkinsona

This comment has been minimized.

Show comment
Hide comment
@wilkinsona

wilkinsona Aug 8, 2016

Member

@mgorniew It's difficult to piece together what might be happening from a stack trace and a single class. Can you please provide a complete sample that reproduces the problem?

Member

wilkinsona commented Aug 8, 2016

@mgorniew It's difficult to piece together what might be happening from a stack trace and a single class. Can you please provide a complete sample that reproduces the problem?

@mgorniew

This comment has been minimized.

Show comment
Hide comment
@mgorniew

mgorniew Aug 8, 2016

Sorry, for no update, but I belive that I found root cause of this issue.

I'm using spring dev-tools and because of that bootRun creates two classloaders. It looks like parent (root) classloader loads cglib library and child classloader (used for reload) will load and create classes from my application. But classes created by cglib library doesn't see private package classes loaded by reload classloader - even if they are in same package (like described here http://stackoverflow.com/a/10470249).

I've fixed this by changing "restart.include" in spring-devtools.properties

mgorniew commented Aug 8, 2016

Sorry, for no update, but I belive that I found root cause of this issue.

I'm using spring dev-tools and because of that bootRun creates two classloaders. It looks like parent (root) classloader loads cglib library and child classloader (used for reload) will load and create classes from my application. But classes created by cglib library doesn't see private package classes loaded by reload classloader - even if they are in same package (like described here http://stackoverflow.com/a/10470249).

I've fixed this by changing "restart.include" in spring-devtools.properties

@wilkinsona

This comment has been minimized.

Show comment
Hide comment
@wilkinsona

wilkinsona Aug 8, 2016

Member

Excellent. Thanks for letting us know you'd figured it out.

Member

wilkinsona commented Aug 8, 2016

Excellent. Thanks for letting us know you'd figured it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment