今天给大家详细解释一项关于Spring的applicationContext.xml文件,这对于初学者来说,应该是很有帮助的,

以下是详解Spring的applicationContext.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-4.0.xsd">

<!-- 注解模式的使用,必须进行扫包 -->
<context:component-scan base-package="com.yw.*"></context:component-scan>
<!-- 引入jdbc.property -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${sqlserver.driver}"></property>
<property name="url" value="${sqlserver.url}"></property>
<property name="username" value="${sqlserver.name}"></property>
<property name="password" value="${sqlserver.pwd}"></property>
<property name="initialSize" value="20"></property>
</bean>

<!-- 创建sqlSessionFactory 工厂-->
<bean id="sessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 引用mybaits的config文件 -->

<!--第一种引入方式,也就是最原始的方法,首先将映射文件引入mybatis的配置文件中,然后再将配置文件引入进来-->
<!-- <property name="configLocation" value="classpath:mybatis.xml" /> -->
<!--也可以直接引入mybatis的mapping文件 name的值不是configurationProperties,而是mapperLocations 这样引入了就不会给实体取别名了 -->

<!--第二种方式,直接将映射文件引入进来,这样就不能给实体取别名了,-->
<!-- <property name="mapperLocations" value="classpath:com/yw/entity/*.xml"/> -->
<property name="mapperLocations" value="classpath:com/yw/entity/jianfusingle.xml"/>
</bean>
<!-- 获取sqlSesion的对象 --><!-- 创建sqlsession时不忘了scope="prototype" -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
<constructor-arg index="0" ref="sessionFactoryBean"/>
</bean>

</beans>

applicationContext.xml详解 spring+mybatis+struts的更多相关文章

  1. applicationContext.xml详解(转)

    转自:http://blog.csdn.net/heng_ji/article/details/7022171,写的很好,省得以后找,放此处 想必用过Spring的程序员们都有这样的感觉,Spring ...

  2. spring applicationContext.xml详解及模板

    applicationContext.xml 文件   1.<context:component-scan base-package="com.eduoinfo.finances.ba ...

  3. Spring中applicationContext.xml详解

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. applicationContext.xml详解

    http://blog.csdn.net/heng_ji/article/details/7022171

  5. 框架基础学习之--详解web+maven+spring+mybatis+struts框架文件夹作用

    详解web+maven+spring+mybatis+struts框架文件夹作用 1.程序名 2.Mybatis,mybatis是数据持久层,就是和对象类有关系的东西 3.存放java文件,xml,p ...

  6. MyBatis Mapper XML 详解

    MyBatis Mapper XML 详解 MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方.对于所有的力量,SQL 映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JD ...

  7. logback的使用和logback.xml详解,在Spring项目中使用log打印日志

    logback的使用和logback.xml详解 一.logback的介绍 Logback是由log4j创始人设计的另一个开源日志组件,官方网站: http://logback.qos.ch.它当前分 ...

  8. spring原理案例-基本项目搭建 02 spring jar包详解 spring jar包的用途

    Spring4 Jar包详解 SpringJava Spring AOP: Spring的面向切面编程,提供AOP(面向切面编程)的实现 Spring Aspects: Spring提供的对Aspec ...

  9. Web.xml详解(转)

    这篇文章主要是综合网上关于web.xml的一些介绍,希望对大家有所帮助,也欢迎大家一起讨论. ---题记 一.            Web.xml详解: (一)  web.xml加载过程(步骤) 首 ...

随机推荐

  1. Android M(6.0) 权限爬坑之旅

    坑一:用Android5.0编译的apk,在Android6.0上运行完全没有问题. 在Android6.0以上才需要在运行时请求权限,在旧Android版本上保留原有逻辑,安装时授予权限. 用旧版本 ...

  2. IOS 整理

    防止程序进入休眠状态 设置应用程序的 idleTimerDisabled 属性为 YES (默认为NO) [UIApplication sharedApplication].idleTimerDisa ...

  3. switch vpn 配置

  4. .NET生成PDF文件

    C#未借助第三方组件,自己封装通用类,生成PDF文件. 调用方式: //路径 string path = @"C:\yuannwu22.pdf"; //内容 string strC ...

  5. php5魔术函数、魔术常量

    魔术函数 1.__construct()  实例化对象时被调用,  当__construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用. 2.__destruct ...

  6. js--小结⑤

    js中的for循环,while循环,do...while循环和C语言的一模一样 有几个问题要提醒一下的是 1.  null是对象,即object       undefined是undefined d ...

  7. 评论一下现有几个开源IM框架(Msn/QQ/Fetion/Gtalk...)

    转载:http://www.cnblogs.com/zc22/archive/2010/05/30/1747300.html 前言 ---------------- 这阵子,在集成通讯框架, 由于不想 ...

  8. Jenkins corbertura问题

    最近在Jenkins上部署项目时遇到无法展示覆盖率测试报告的问题. build success后,出现配置的覆盖率报告存储位置not exists的失败问题,评估是Jenkins每次按照publish ...

  9. Android - 向服务器发送数据(GET).

    在此,使用HTTP协议,通过GET请求,向服务器发送请求,这种方式适合于数据量小,数据安全性要求不高的情况下. 一,服务器端,使用Servlet. 在服务器端,定义一个HttpServlet的子类,以 ...

  10. (转)VS自带工具:dumpbin的使用

    有时候我们想查看一个exe引用了哪些动态库,或者我们想看某个动态库包含哪些接口函数,这个时候可以使用dumpbin.exe工具: 1.输入Dumpbin -imports calldll.exe查看它 ...