-
Dec 6th, 2012, 01:04 AM
#1
How to instantiate beans of same type with different bean ids using JavaConfig ?
In the simple case for one bean definition in XML would be say :
<beans>
<bean id="helloWorld" class="com.blah.HelloWorld" />
</beans>
The equivalent of this in JavaConfig would be:
package com.blah;
import org.springframework.context.annotation.*;
@Configuration
public class HelloWorldConfig {
@Bean
public HelloWorld helloWorld(){
return new HelloWorld();
}
}
So extending this to more than one bean
<beans>
<bean id="helloWorld" class="com.tutorialspoint.HelloWorld" />
<bean id="helloWorldAgain" class="com.tutorialspoint.HelloWorld" />
</beans>
What would be equivalent JavaConfig to this?
-
Dec 6th, 2012, 02:23 AM
#2
Please use [ codce][/code ] tags when posting code...
SImply define 2 beans, the method name is the bean name (or specify the name in the Bean annotation).
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