当前位置: 首页 > >

一个xml文件拆分成多个xml文件

发布时间:

该文章是基于前一篇文章中beans.xml的拆分,详情请看
spring.xml



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">




init-method="init" destroy-method="close">













Spring-dao.xml



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">







spring-service.xml



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">








spring-control.xml



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">








测试类:


package com.test.demo;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import com.alibaba.druid.pool.DruidDataSource;
import com.bean.User;
import com.web.controller.UserController;

/**
* 案例测试类
*/
@RunWith(SpringRunner.class)
//@ContextConfiguration("classpath:beans.xml")
@ContextConfiguration("classpath:spring.xml")
public class DemoTest {
@Autowired
private UserController userController;

@Test
public void testWithoutSpring() {
DruidDataSource ds = new DruidDataSource();
ds.setUsername("root");
ds.setPassword("root");
ds.setUrl("jdbc:mysql://localhost:3306/test");
ds.setDriverClassName("com.mysql.jdbc.Driver");
System.out.println(ds);
}

@Test
public void testAdd() {
int result = userController.add();
System.out.println(result == 1 ? "添加成功" : "添加失败");
}

@Test
public void testQuery() {
List users = userController.query();
for (User user : users) {
System.out.println(user);
}
}
}



友情链接: