AndreaNobili
AndreaNobili

Reputation: 42957

Beans Java Based Configuration in Spring Framework, don't work

I am reading this article about Spring Java Based Configuration. I am creating an example similar to the one in this tutorial, but I'm using Maven for the build process.

I have added the following dependencies to my project: spring-core, spring-bean, spring-context, spring-context-support and spring-asm.

The problem is that when I try to execute my application I obtain the following error message:

feb 13, 2013 10:26:49 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4ba4536d: startup date [Wed Feb 13 10:26:49 CET 2013]; root of context hierarchy
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: [helloWorldConfig]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:327)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:222)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:620)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
    at org.andrea.myexample.myJavaConfiguration.MainApp.main(MainApp.java:13)

Reading online I have understood that to use these annotations (@Configuration and @Bean) I have to add the spring-asm dependencies to my project. I have tried but it didn't work.

This is my entire pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.andrea.myexample</groupId>
<artifactId>myJavaConfiguration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>myJavaConfiguration</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-asm</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
</dependencies>

Can someone help me?

Upvotes: 2

Views: 4885

Answers (3)

09Q71AO534
09Q71AO534

Reputation: 4440

For The Article Which u have Read .

To Make It Work u just Add theCGLIB Jar File into your Project.

Download the Jar from CGLIB Jar link and Add it to your Project

If u r using MAVEN then, you need to include the CGLIB library manually, just declares it in Maven pom.xml file.

 <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

Upvotes: 0

Xavi L&#243;pez
Xavi L&#243;pez

Reputation: 27880

In the very same tutorial page it is stating that you need to have the CGLib jar in your classpath (emphasis added):

Let us have working Eclipse IDE in place and follow the following steps to create a Spring application:

...
3 - Because you are using Java-based annotations, so you also need to add CGLIB.jar from your Java installation directory and ASM.jar library which can be downloaded from asm.ow2.org.
...

With Maven, you'll need to add the following dependency into your pom.xml:

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2.2</version>
</dependency>

Source

Upvotes: 6

Sajan Chandran
Sajan Chandran

Reputation: 11487

Add the below depedency in your pom it should work.

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2.2</version>
</dependency>

Upvotes: 4

Related Questions