-
Aug 18th, 2010, 06:46 AM
#1
Injection another class to the same field in parent class and child
I'm not good at English, sorry.
Please teach the way of injection another class to the same field in parent class and child class.
Version:Spring 2.5.6
For example, there is ClassA that have a field.
Class "Bean" is injected into the field of ClassA by the @Autowired and @Qualifier.
@Component
public class ClassA{
@Autowired
@Qualifier("bean")
protected Bean bean;
}
@Component
public class Bean{
}
@Component
public class ClassB extends ClassA{
}
@Component
public class ExtendsBean extends Bean{
}
I want to do follows.
Class "Bean" is injected into the field "bean" of ClassA,
Class "ExtendsBean" is injected into the field "bean" of ClassB.
Show me how to do it.
I done it as follows. But I don't know this is correct way.
@Component
public class ClassB extends ClassA{
@Autowired
public void setBean(ExtendsBean bean){
super.bean = bean;
}
}
It looks like it act below.
1. field @Autowired injection was done.
2. method @Autowired injection was done.
Is this sequence right in specification?
Is not the injection sequence defined in specifications?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules