1 Load the custom beans.xml file
@Test
public void testAutoWire() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("ioc/autoWire/beanAutoWire.xml");//加载包ioc.autoWire下面的beanAuthWire.xml文件UserService service = (UserService)ctx.getBean("userServiceAutoWire");System.out.println(service.getUserDAOautoWire());}
2 Load multiple bean.xml files in the main beans.xml (there are bean files such as beanAutoWire1.xml, beanAutoWire2.xml under the ioc.autoWire package)
One is configured in web.xml
Add the following
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/beans.xml,/WEB-INF/ioc/autoWire/beanAutoWire.xml,/WEB-INF/ioc/autoWire/beanAutoWire2.xml
</param-value>
</context-param>
Separate multiple beans.xml with commas
two
Configured in the main benas.xml as follows
<import resource="ioc/autoWire/beanAutoWire1.xml"/>
<import resource="ioc/autoWire/beanAutoWire2.xml"/>
This completes the configuration