本文主要是介绍vue+element+git+maven+springMVC+springBoot+MyBatis-电力监理生产业务管理系统-2.3 测试并配置spring framework,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
测试并配置spring framework
- 1.建立相关对象
- 1.1建立User
- 1.2建立UserDao接口
- 1.3建立UserDaoImpl实现
- 1.4建立UserDaoTest测试程序
- 2.配置spring
- 2.1配置applicationContext
- 3.项目文件结构
- 4.测试结果
- 总结
- 项目目录
1.建立相关对象
1.1建立User
代码如下(示例):
package cn.lilinghui.jlemip.bean;public class User {private String name;private int id;private int age;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getId() {return id;}public void setId(int id) {this.id = id;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}}
1.2建立UserDao接口
代码如下(示例):
package cn.lilinghui.jlemip.dao;public interface UserDao {public void save();
}
1.3建立UserDaoImpl实现
代码如下(示例):
package cn.lilinghui.jlemip.dao.impl;import cn.lilinghui.jlemip.bean.User;
import cn.lilinghui.jlemip.dao.UserDao;public class UserDaoImpl implements UserDao {public void save() {User user = new User();user.setName("llh");System.out.println("save..." + user.getName());}}
1.4建立UserDaoTest测试程序
代码如下(示例):
package cn.lilinghui.jlemip.test;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.lilinghui.jlemip.dao.UserDao;
import cn.lilinghui.jlemip.dao.impl.UserDaoImpl;public class UserDaoImplTest {public static void main(String[] args) {@SuppressWarnings("resource")ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");UserDao userDao = applicationContext.getBean(UserDaoImpl.class);userDao.save();}
}
2.配置spring
2.1配置applicationContext
代码如下(示例):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><bean id="userDao" class="cn.lilinghui.jlemip.dao.impl.UserDaoImpl"></bean>
</beans>
3.项目文件结构
4.测试结果
结果如下:
08:54:43.360 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7b3300e5
08:54:43.569 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 1 bean definitions from class path resource [applicationContext.xml]
08:54:43.665 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'userDao'
save...llh
总结
以上就是今天要讲的内容,本文仅仅简单介绍了spring framework的使用、简单的配置及测试,接下来的章节,我们将引入更多详细的配置、说明及测试。
项目目录
vue+element+git+maven+springMVC+springBoot+MyBatis-电力监理生产业务管理系统 目录
这篇关于vue+element+git+maven+springMVC+springBoot+MyBatis-电力监理生产业务管理系统-2.3 测试并配置spring framework的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!