zoukankan      html  css  js  c++  java
  • 【Spring】application.xml文件配置

    什么是Spring

    Spring是分层的javaEE full-stack(一站式)轻量级开源框架。

    ---注解配置--针对SSM

    <?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
    <!-- 导入外部资源文件

                  FALLBACK   默认值,不存在时覆盖
                  NEVER    不覆盖
                  OVERRIDE  覆盖
    -->
    <context:property-placeholder location="classpath:db.properties" system-properties-mode="FALLBACK"/>

    <!--
    注解配置扫描
    -->
    <!-- 扫描 service dao -->
    <context:component-scan base-package="com.hp"></context:component-scan>
    <!-- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <!-- 数据库连接的四要素 -->
    <property name="driverClassName" value="${jdbc.driverClass}"></property>
    <property name="url" value="${jdbc.jdbcUrl}"></property>
    <property name="username" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
    </bean>
    <!-- 注册事务管理器 -->
    <bean id="txMgr"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 开启事务注解驱动 -->
    <tx:annotation-driven transaction-manager="txMgr" />

    <!-- 配置mybatis的sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="configLocation" value="classpath:mybatis-config.xml"></property>
    </bean>

    <!-- 配置可以整体扫描Mapper的一个扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.hp.bookstore.mapper"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    </beans>

    db.properties数据库连接文件内容:

    jdbc.user=xxx
    jdbc.password=xxx
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.jdbcUrl=jdbc:mysql://localhost:3306/xxx?useSSL=true

    学着把生活的苦酒当成饮料一样慢慢品尝, 不论生命经过多少委屈和艰辛, 我们总是以一个朝气蓬勃的面孔, 醒来在每一个早上。
  • 相关阅读:
    poj3417 闇の連鎖 【树上差分】By cellur925
    Luogu P1613跑路【倍增】By cellur925
    CF519E A and B and Lecture Rooms
    poj 2412 The Balance 【exgcd】By cellur925
    NOIp 2014 解方程 【数学/秦九韶算法/大数取膜】By cellur925
    Maven项目整合SSH框架
    传递依赖
    Maven项目整合Struts2框架
    K.O. -------- Eclipse中Maven的报错处理
    依赖范围
  • 原文地址:https://www.cnblogs.com/yhm9/p/10502897.html
Copyright © 2011-2022 走看看