spring管理
spring管理
SqlMapConfig.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           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.xsd"
    >
        <context:property-placeholder location="classpath:db.properties"/>
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${db.driver}"/>
            <property name="username" value="${db.username}"/>
            <property name="password" value="${db.password}"/>
            <property name="url" value="${db.url}"/>
        </bean>
        <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="configLocation" value="SqlMapConfig.xml"/>
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <bean id="testMapper" class="daoImpl.TestMapperImpl">
            <property name="sqlSessionFactory" ref="sessionFactory"/>
        </bean>
        <!--<bean id="testMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">-->
            <!--<property name="mapperInterface" value="mapper.TestMapper"/>-->
            <!--<property name="sqlSessionFactory" ref="sessionFactory"/>-->
        <!--</bean>-->
        <!-- Mapper代理的方式开发方式二,扫描包方式配置代理
        每个mapper代理对象的id就是类名,首字母小写
        -->
        <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">-->
            <!--<property name="basePackage" value="mapper"/>-->
            <!--<property name="sqlSessionFactoryBeanName" value="sessionFactory"/>-->
        <!--</bean>-->
    </beans>
impl:
    public class TestMapperImpl extends SqlSessionDaoSupport implements TestMapper {
        public List<Test> selectByReg() {
            return getSqlSession().selectList("selectByReg");
        }
    }
测试:
    public class SpringTest2 {
        @Test
        public void test1(){
            ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
    //        TestMapperImpl bean = context.getBean(TestMapperImpl.class);
            TestMapper mapper = (TestMapper) context.getBean("testMapper");
            List<mapper.Test> list = mapper.selectByReg();
            System.out.println(list);
        }
    }
spring管理的更多相关文章
- Spring 管理数据源
		Spring 管理数据源 不管通过何种持久化技术,都必须通过数据连接访问数据库,在Spring中,数据连接是通过数据源获得的.在以往的应用中,数据源一般是Web应用服务器提供的.在Spring中,你不 ... 
- 将spring管理的bean使用注解的方式注入到servlet中
		Filter和Servlet中不能直接注解使用spring的bean,因为这两个都是servlet容器维护管理的,当然也有实现方法,如下: 1.创建一个AbstractServlet 抽象类,让你的所 ... 
- ssh整合随笔(注解方式,Spring 管理action)
		Web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ... 
- 通过案例掌握Spring 管理事务的步骤及配置
		案例描述 通过完成生成订单业务,掌握事务处理. 需要d_order表和d_item表 订单生成时的业务逻辑:向d_order插入1条数据的同时,向t_item中插入若干条数据 这就是一个独立的 ... 
- Spring管理Hibernate
		为什么要用Hibernate框架? 既然用Hibernate框架访问管理持久层,那为何又提到用Spring来管理以及整合Hibernate呢? 首先我们来看一下Hibernate进行操作的步骤.比如添 ... 
- 【转】spring管理属性配置文件properties——使用PropertiesFactoryBean|spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
		spring管理属性配置文件properties--使用PropertiesFactoryBean 对于属性配置,一般采用的是键值对的形式,如:key=value属性配置文件一般使用的是XXX.pr ... 
- 怎么随时获取Spring的上下文ApplicaitonContext,和Spring管理的Bean
		BeanFactory接口 Interface BeanFactory getBean <T> T getBean(String name, Class<T> required ... 
- 为何在新线程中使用注解获取不到Spring管理的Bean
		新建的线程类NewThread,在这个类中国使用Spring的注解获取Service,为null 网上已有这种问题的解决方案,但是为何在新线程中使用注解获取不到Spring管理的Bean? 问了老大, ... 
- ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存
		ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate : Hibernate是一个持久层框架,经常访问物理数据库 ... 
- spring管理的类如何调用非spring管理的类
		spring管理的类如何调用非spring管理的类. 就是使用一个spring提供的感知概念,在容器启动的时候,注入上下文即可. 下面是一个工具类. import org.springframewor ... 
随机推荐
- Linux系统默默改变了人类世界的生活方式
			你知道操作系统都有些什么吗?Windows啊.这是我在上大学之前的问答,我当时认为只一种叫做Windows的操作系统,可是我错了,当我上大学以后,作为计算机专业的一名学生的时候我第一次接触到了除Win ... 
- day5-python数据类型
			数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定 ... 
- jsp标签之jsp:setProperty用法
			参考:http://blog.csdn.net/wanghaishanren/article/details/2047400 
- XML(二)
			XML XML介绍 1.什么是xml? 概念:XML(EXtensible Markup Language)XML 指可扩展标记语言(EXtensible Markup Language) 可扩展:我 ... 
- TCP拥塞控制和流量控制
			TCP 的流量控制与拥塞控制可以说是一体的.流量控制是通过滑动窗口实现的,拥塞避免主要包含以下2个内容: (1)慢开始,拥塞避免 (2)快重传,快恢复 1.流量控制——滑动窗口 TCP采用大小可变 ... 
- 福大软工1816 · 第三次作业 - 结对项目Salty Fish原型图
			SALTY FISH原型图 LINKS IMPORT to LIST FOCUS TRENDS ANALYSE NIGHT 
- [Leetcode221]最大面积 Maximal Square
			[题目] Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's a ... 
- 深入理解java虚拟机---虚拟机工具jps与jstat(十四)
			jps-java process status jps类似于linux的ps命令,用于查看进程. JPS 名称: jps - Java Virtual Machine Process Status T ... 
- 关于Java的接口
			其实刚开始听到接口的时候不解其意,为什么要有接口这个东西,加之老师上课我可能没仔细听(或者时间长了忘了?),这次看到了“用接口设计并实现圆,三角形,矩形的面积与周长计算”这个题目的代码,它将接口定义在 ... 
- <Spark><Spark Streaming>
			Overview Spark Streaming为用户提供了一套与batch jobs十分相似的API,以编写streaming应用 与Spark的基本概念RDDs类似,Spark Streaming ... 
