@import in springs examples.
package multiconfig;
public class Naveen {
public void print(String msg)
{
System.out.print("Naveen"+msg);
}
}
package multiconfig;
public class Jyoti {
public void print(String msg)
{
System.out.print("Naveen"+msg);
}
}
public class Naveen {
public void print(String msg)
{
System.out.print("Naveen"+msg);
}
}
package multiconfig;
public class Jyoti {
public void print(String msg)
{
System.out.print("Naveen"+msg);
}
}
package multiconfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Naveenconfig {
@Bean(name="naveen")
public Naveen n()
{
return new Naveen();
}
}
package multiconfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Jyoticonfig {
@Bean(name="jyoti")
public Jyoti j()
{
return new Jyoti();
}
}
package multiconfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({ Naveenconfig.class, Jyoticonfig.class })
public class Appconfig {
}
package multiconfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String args[])
{
ApplicationContext tx=new AnnotationConfigApplicationContext(Appconfig.class);
Naveen n=(Naveen)tx.getBean("naveen");
n.print("NaveenJyoti");
Jyoti j=(Jyoti)tx.getBean("jyoti");
j.print("NaveenJyoti");
}
}