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>

    生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
  • 相关阅读:
    700. Search in a Binary Search Tree
    100. Same Tree
    543. Diameter of Binary Tree
    257. Binary Tree Paths
    572. Subtree of Another Tree
    226. Invert Binary Tree
    104. Maximum Depth of Binary Tree
    1、解决sublime打开文档,出现中文乱码问题
    移植seetafaceengine-master、opencv到ARM板
    ubuntu16.04-交叉编译-SeetaFaceEngine-master
  • 原文地址:https://www.cnblogs.com/ysq0908/p/5156555.html
Copyright © 2011-2022 走看看