博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Spring】application.xml文件配置
阅读量:7226 次
发布时间:2019-06-29

本文共 2626 字,大约阅读时间需要 8 分钟。

什么是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

转载于:https://www.cnblogs.com/yhm9/p/10502897.html

你可能感兴趣的文章
什么是Javascript函数节流?
查看>>
MQ框架的比较
查看>>
oschina
查看>>
Octave 入门
查看>>
深度学习入门:10门免费线上课程推荐
查看>>
React组件设计模式(一)
查看>>
E-HPC支持多队列管理和自动伸缩
查看>>
express + mock 让前后台并行开发
查看>>
30天自制操作系统-2
查看>>
小程序开发之路(一)
查看>>
Odoo domain写法及运用
查看>>
JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
查看>>
猫头鹰的深夜翻译:Java 2D Graphics, 简单的仿射变换
查看>>
面试题:给你个id,去拿到name,多叉树遍历
查看>>
go append函数以及写入
查看>>
关于Java中分层中遇到的一些问题
查看>>
配置 PM2 实现代码自动发布
查看>>
android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
查看>>
iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
查看>>
诡异!React stopPropagation失灵
查看>>