Can We Have Multiple Spring Configuration Files in One Project? If yes, can someone provide a working example to support this concept?
Advertisement
Answer
Yes, in large projects, having multiple Spring configurations increase maintainability and modularity.
You can load multiple files like this:-
@Configuration @Import({MainConfig.class, SchedulerConfig.class}) public class AppConfig {
You can also upload one XML file that will contain all configs.
ApplicationContext context = new ClassPathXmlApplicationContext("spring-all.xml");
inside the XML file:-
<import resource="main.xml"/> <import resource="scheduler.xml"/>