How to add parent class using spring annotation

the parent class is as follows:

public class BaseDAO{ private DBRoute defaultDB; public DBRoute getDefaultDB() { return this.defaultDB; } public void setDefaultDB(DBRoute defaultDB) { this.defaultDB = defaultDB; } } 

I created beans as shown below:

 <bean id="adsConfigDB" class="net.flyingfat.common.dbroute.config.DBRoute"> <constructor-arg value="adsConfig" /> </bean> <bean id="adsBizDateDB" class="net.flyingfat.common.dbroute.config.DBRoute"> <constructor-arg value="adsBizDate" /> </bean> 

I want to add the superclass defaultDB property to a subclass via byName, and not by the type that is in the subclass, to insert defaultDB using adsConfigDB or adsBizDateDB . Is there a way to do this using spring annotations? I already tried Autwired or Resource with a constructor that doesn't work. By the way, I already know that this can be done using XML.

+5
source share
1 answer

@Qualifier annotation - This annotation is used to prevent conflicts in the display of the bean, and we need to provide a bean name that will be used for auto-preparation. This way we can avoid problems when several beans are defined for this type. This annotation usually works with the @Autowired annotation. For constructors with multiple arguments, we can use this annotation with the argument names in the method.

Your code will be like this.

 @Autowired @Qualifier("adsConfig") private DBRoute defaultDB; 
+1
source

All Articles