zoukankan      html  css  js  c++  java
  • applicationContext.xml详解 spring+mybatis+struts

    今天给大家详细解释一项关于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>

    生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
  • 相关阅读:
    Teched最后两天下载,同时新加熊老的teched录像,请尽快下载。
    如何学习,牛人是否真牛?
    为什么我的脚本大多是支持IE环境
    SPS中提供的Blog
    teched2004最后一天下载,新增js的menu1.0下载
    asp+xml+js所作的文件管理器,完全仿xp风格,精彩下载不要错过。
    将业务系统数据库的数据显示在页面上并且作WebPart的跨页面连接
    Activity中UI框架基本概念
    Android学习笔记——Activity的启动和创建
    Mms模块ConversationList流程分析(2)
  • 原文地址:https://www.cnblogs.com/ysq0908/p/5156555.html
Copyright © 2011-2022 走看看