Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load configuration class

Tags:

java

spring

I am following this tutorial about how to use Spring and based on the provided example, I get the following exception:

Exception in thread "main" java.lang.IllegalStateException: Cannot load configuration class: com.tutorialspoint.HelloWorldConfig
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:378)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
    at com.tutorialspoint.MainApp.main(MainApp.java:9)
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
    at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:128)
    at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:100)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:368)
    ... 7 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
    at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
    ... 12 more
Caused by: java.lang.SecurityException: class "com.tutorialspoint.HelloWorldConfig$$EnhancerBySpringCGLIB$$b5aece24"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
    ... 18 more

I have researched my problem and have found this; someone also has had the same problem as me, and it has something to do with ensuring that ASM is compatible with CGLIB. However I have tried this solution and it has not worked, I even went as far as using the exact same versions as the one provided (GBLIB 2.2.2 and ASM 3.3.1).

What do I need to do in order to correct this?


For simplicity, here are the files which I am using that were extracted from the provided tutorial.

HelloWorldConfig.java

package com.tutorialspoint;
import org.springframework.context.annotation.*;

@Configuration
public class HelloWorldConfig {

    @Bean
    public HelloWorld helloWorld() {
        return new HelloWorld();
    }
}

HelloWorld.java

package com.tutorialspoint;

public class HelloWorld {
    private String message;

    public void setMessage(String message) {
        this.message = message;
    }

    public void getMessage() {
        System.out.println("Your Message : " + message);
    }
}

MainApp.java

package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

public class MainApp {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        ApplicationContext ctx = new AnnotationConfigApplicationContext(
                HelloWorldConfig.class);

        HelloWorld helloWorld = ctx.getBean(HelloWorld.class);

        helloWorld.setMessage("Hello World!");
        helloWorld.getMessage();
    }
}

Also by saying 'However I have tried this solution and it has not worked' I mean that the exact same error is returned.

like image 989
Kurtiss Avatar asked Feb 21 '26 11:02

Kurtiss


2 Answers

I had the same problem and realized the JRE version I have in the POM.xml or the default one associated with the project was not set in the class path. So updated the same under Preferences -> Installed JREs and ran the application it worked.

like image 130
Mahesh Avatar answered Feb 24 '26 00:02

Mahesh


Gone through this problem yesterday and Here is the solution.

  1. Open Eclipse
  2. Open window in menu bar -> preferences -> java ->installed jre
  3. add new jre which is installed in system(c:program_files->java->jre->bin) add it.
  4. Select the new added jre and BOOOM 🔥🔥
like image 40
Hritik manbattulwar Avatar answered Feb 24 '26 00:02

Hritik manbattulwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!