Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGLIB is required to process @Configuration classes

Tags:

spring

Am using Spring 3.1. War is not built using Maven. Its just a normal build. I have below jars in my class path.

antlr-runtime-3.0.1.jar
commons-logging-1.1.1.jar
org.apache.commons.logging.jar
org.springframework.aop-3.1.0.M2.jar
org.springframework.asm-3.1.0.M2.jar
org.springframework.aspects-3.1.0.M2.jar
org.springframework.beans-3.1.0.M2.jar
org.springframework.context-3.1.0.M2.jar
org.springframework.context.support-3.1.0.M2.jar
org.springframework.core-3.1.0.M2.jar
org.springframework.core-3.1.0.RELEASE.jar
org.springframework.core.jar
org.springframework.expression-3.1.0.M2.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar

I have below code,

@Configuration
public class AppConfig {

    @Bean(name="helloBean")
    public HelloWorld helloWorld()
    {
        return new HelloWorldImpl();
    }
}

When I run main method, am getting below exception

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: [appConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:297)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigurationClasses(ConfigurationClassPostProcessor.java:200)

To overcome this, if I add cglib-2.1.jar, am getting below exception..

java.lang.ClassNotFoundException: org.objectweb.asm.Type

To overcome this, if I add asm3.1.jar, am getting below exception.

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.

How can I overcome my initial exception - CGLIB is required to process @Configuration classes ?

like image 965
user2488578 Avatar asked Aug 14 '13 06:08

user2488578


People also ask

Why do we need @configuration in spring boot?

One of the most important annotations in spring is @Configuration annotation which indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application. This annotation is part of the spring core framework.

What is Cglib?

CGLIB is a powerful, high performance code generation library. It is complementary to the JDK dynamic proxy in that it provides proxying classes that do not implement interfaces. Under the covers, it uses ASM bytecode manipulation framework.


2 Answers

War is not built using Maven. Its just a normal build

Your problem exactly highlights why you should use Maven (or other similar dependency tool) -- congratulation on learning things the hard way. Libraries in Java world often have a very complex dependency tree and Maven can help resolve it all for you.

In your case, had you used maven you just need to include cglib dependency and all its transitive dependency (including asm) will be resolved for you

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.0</version>
</dependency>
like image 116
gerrytan Avatar answered Sep 28 '22 22:09

gerrytan


Starting with Spring 3.2, it is no longer necessary to add cglib as an explicit dependency.

Reference: http://www.baeldung.com/2011/10/20/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1/#cglib_gone

This answer for those who wondered why their project running normally without cglib, and come to this page searching for info about cglib as me.

like image 41
Erlan Avatar answered Sep 28 '22 20:09

Erlan