When you are working on complex application, it is not good practice to have only single xml configuration, you can split it into multiple file for better maintenance.
There are two ways to do it.
- Using application context constructor
- Using import in xml bean
Using application context constructor:
1 2 3 4 5 |
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring-service.xml", "spring-businessObjects.xml"}); |
Using import:
You can do it using import tag too.
Lets say you have spring-service.xml as below:
1 2 3 4 5 |
<!--?xml version="1.0" encoding="UTF-8"?--> |
You have another spring configuration called spring-businessObjects.xml as below:
1 2 3 4 5 |
<!--?xml version="1.0" encoding="UTF-8"?--> |
You can simply import above two files in another xml file called applicationcontext.xml. You need to load applicationcontext.xml to load all bean objects.
1 2 3 4 5 |
<!--?xml version="1.0" encoding="UTF-8"?--> |