I have a doubt in using beans generated by another project. To be more detail :
I have a project A as follows
public A {
public void print()
{
System.out.println("Hello World");
}
}
The config class is as follows
@Configuration
public class AConfig {
@Bean
public A a()
{
A bean = new A();
return A;
}
}
Now I have a new project B which has class as follows
public B {
A a;
public setA()
{
this.a = a;
}
public static void main(String[] args)
{
System.out.println(a.print());
}
}
config class for B as follows
@Configuration
@Import(AConfig.class)
public BConfig
{
@Bean
public B b()
{
B bean = new B();
**b.setA(a());-----------------This is not correct. How can i get Instance of class A NOw????**
}
}
Thanks
Merge
@ConfigurationclassesIf beans are tightly coupled, just put them in the same class:
Inject another
@Configurationclass@Configurationclass is just a special case of a bean in Spring:Inject dependencies to
@Configurationclass