1

I am working with version Spring 4.0 and learning DI in Java. I have a Shape interface and once class that implements it:

@Component
@Lazy
@Scope(value="prototype")
public class Circle implements Shape {
    public Circle() {
        System.out.println("Ctor Circle");
    }
    @Override
    public double GetArea() {
        // TODO Auto-generated method stub
        return 2.0;
    }
}

and simple class which will get the shape in injection

@Service
@Lazy
public class ShapeHolder {
    @Autowired
    //@Lazy
    private Shape cShape; 

    public ShapeHolder() {
        System.out.println("Ctor shapeHolder");
    }
}

when the @Lazy above the field is commented all is working however when it isn't commented, I am getting exception

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shapeHolder': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.base.Interfaces.Shape com.base.services.ShapeHolder.cShape; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

Am I doing something wrong? I want that the injection will be real Lazy.

1 Answer 1

1

There is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice, spring lazy initialization depdens on aopalliance jar

If you are using maven, you need to add the following dependency.

<dependency>
    <groupId>aopalliance</groupId>
    <artifactId>aopalliance</artifactId>
    <version>1.0</version>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.