Priyanka L Verma
Priyanka L Verma

Reputation: 41

Can abstract class be autowired in another class?

Can abstract class be autowired in another class?

Suppose we have a bean

     <bean id = "Utils" class = "com.org.appl.Utils" abstract = "true">
          <property name = "javaUtils" ref = "javaUtils"/>
        </bean>

can we use this

bean like:

      Public class Calculation


   {
    @Autowired
    private Utils utils;
    .......................
    }

Upvotes: 0

Views: 417

Answers (1)

Klaus Groenbaek
Klaus Groenbaek

Reputation: 5035

NO

abstract=true is used in spring-xml files to create a group of properties, it is not the same as an abstract class.

Abstract classes can't be @Autowired because they can't be created, this is how Java work.

There are cases where Spring will take an abstract class and create an implementation at runtime, by using CGLIB to emit bytecode, for instance when using lookup method injection

Upvotes: 1

Related Questions