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>

    生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
  • 相关阅读:
    the process cannot access the file because it is being used by another process
    SharePoint 2013: The "New Web Application" button is disabled is the central administration
    【转】Windows按键消息—虚拟键码
    【转】windows消息16进制对应表
    C#将图片字节流转为Base64直接放入html的img标签src属性中
    WPF自定义Main函数
    c#geckofx文件流下载
    腾讯RTX登录提示失败问题及处理办法
    C# \u8888类型的unicode转换为字符串方法
    C#System.Net.Mail采用简单邮件传输协议发送邮件
  • 原文地址:https://www.cnblogs.com/ysq0908/p/5156555.html
Copyright © 2011-2022 走看看