0

SportConfig.java

package luv2code;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.ComponentScan;

import org.springframework.context.annotation.Configuration;


@Configuration

public class SportConfig {

//  define bean for our sad fortune service

    @Bean
    public Fortune sadfortuneService() {
         return new SadFortuneService();
    }
    
//  define bean for our swim coach AND inject dependency
    
    @Bean 
    public Coach swimCoach() {
        return new SwimCoach(sadfortuneService());
    }
}

When I run main method, am getting the exception below:

Exception in thread "main" java.lang.IllegalStateException: CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove the following @Configuration bean definitions: [sportConfig]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:214)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:145)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:65)
    at luv2code.JavaConfiguartionDemoApp.main(JavaConfiguartionDemoApp.java:9)
dan1st
  • 12,568
  • 8
  • 34
  • 67

1 Answers1

0

I guess you did not set up your Spring Boot project in the simplest way using a proper build tool like Maven or Gradle, see this question:
CGLIB is required to process @Configuration classes I recommend that you start from scratch and follow on of the classic tutorials to setup a new Spring Boot project, so that you will not face the IllegalStateException.

If you can use your IDE (Eclipse or IntelliJ) to setup a Spring Boot project, try it this way. In my German blog I have written a step by step tutorial to do it with Eclipse:
https://agile-coding.blogspot.com/2020/09/microservices-mit-spring-boot-erstellen.html

Elmar Brauch
  • 1,286
  • 6
  • 20