murthy
murthy

Reputation: 192

Spring @Component with Parent

Is there a way to define the Parent class for annotated with @Component. We are having a mix of Annotations and XML definitions

@Component
public class BaseClass extends SuperClass
{
}

/**
* This bean is defined in the XML and made as abstract
*/
public abstract class SuperClass extends VerySuperClass
{
}

/**
* This bean is defined in the XML and made as abstract
*/
public abstract class VerySuperClass
{
    protected IEmployeeDAO employeeDAO;
    protected ITableDAO tableDAO;
}

The problem here is with the Annotation and it is not inheriting its parent defined properties which are getting as null in the BaseClass.java.

I know that If we defined as XML bean this works, but if there is a way to say its parent through Annotation.

Thanks in advance

Upvotes: 2

Views: 5870

Answers (1)

Avinash
Avinash

Reputation: 4279

Your VerySuperClass should Autowire the DAOs to have those instances.

public abstract class VerySuperClass {

    @Autowired
    protected IEmployeeDAO employeeDAO;

    @Autowired
    protected ITableDAO tableDAO;
}

Now with BaseClass bean you can access VerySuperClass beans.

I have created blow example for your better understanding.

https://github.com/avinashroy/spring.di.componentHierarchy

Upvotes: 2

Related Questions