1:Spring的核心配置文件中的各种配置。

spring的核心配置文件的名字 叫做 applicationContext.xml,后期也可以通过配置文件修改名称,在web.xml中进行如下修改:

 <context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/applicationContext*.xml</param-value></context-param>

2:核心配置文件中关于dao层的配置。(1):首先准备db.properties 配置文件,最简单的配置如下。

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456

(2):然后在核心配置文件中加载数据库文件.

<context:property-placeholder location="classpath:resource/db.properties" />

(3):配置数据库连接池,配置类可以用BasicDatasource,也可以用阿里的配置核心类 DruidDataSource。

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"destroy-method="close"><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="driverClassName" value="${jdbc.driver}" /><property name="maxActive" value="10" /><property name="minIdle" value="5" /></bean>

后期需要可以在其中添加多个属性配置。

(4):Spring和hibernate,和mybatis的整合主要是整合sessionFactory.
     和hibernate的一个整合。

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!-- 与dataSource --><property name="dataSource"><ref bean="dataSource"/></property>
</bean>

和mybatis的一个整合.

<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 数据库连接池 --><property name="dataSource" ref="dataSource" /><!-- 加载mybatis的全局配置文件 --><property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /></bean>

(5):配置文件中关于事务的配置。<

!-- 事务管理器 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 数据源 --><property name="dataSource" ref="dataSource" /></bean>

配置通知。

<!-- 通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 传播行为 --><tx:method name="save*" propagation="REQUIRED" /><tx:method name="insert*" propagation="REQUIRED" /><tx:method name="add*" propagation="REQUIRED" /><tx:method name="create*" propagation="REQUIRED" /><tx:method name="delete*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="find*" propagation="SUPPORTS" read-only="true" /><tx:method name="select*" propagation="SUPPORTS" read-only="true" /><tx:method name="get*" propagation="SUPPORTS" read-only="true" /></tx:attributes></tx:advice>

关于切面的配置。

<!-- 切面 --><aop:config><aop:advisor advice-ref="txAdvice"pointcut="execution(* com.store.service.*.*(..))" /></aop:config>

关于service层的配置。     扫描包下面所有的service层。

<context:component-scan base-package="com.xiaoao.service"/> 

关于注解驱动的配置

<mvc:annotation-driven />

(6):在进行配置的时候所需要引入的命名空间。

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/s ... ing-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx       http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

jar包导入的话,可以使用maven管理,非常方便。

关于Spring核心配置文件中的各项主要配置相关推荐

  1. c3p0连接池配置Spring核心配置文件中配置applicationContext.xml

    1.1 配置c3p0.properties属性文件 #c3p0连接池属性文件 # 四大基本信息 c3p0.driverClass=com.mysql.jdbc.Driver #这里需要改成你自己的数据 ...

  2. spring核心配置文件引入外部properties文件和另外的xml配置文件

    spring核心配置文件引入外部properties文件和另外的xml配置文件 为什么要引入外部文件 我们使用jdbc的时候,会创建一个jdbc.properties配置文件,如果我需要在spring ...

  3. 【SpringBoot零基础案例09】【IEDA 2021.1】SpringBoot将核心配置文件中的自定义配置映射到一个对象

    使用@Value注解获取核心配置文件中的值时只能是一个一个的获取,如果在配置文件中有多个对象需要用到名称一样的配置,如name.age等属性,则需要区分是这个属性是哪个对象的.因此可以将这些配置映射到 ...

  4. JDBC.property 配置文件中链接数据库的配置

    JDBC.property 配置文件中链接数据库的配置 #sqlserver数据源配置 jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLSer ...

  5. Java|Kotlin, SpringBoot从配置文件中读取@KafkaListener参数配置

    springboot从配置文件中设置@KafkaListener参数配置 在java中使用占位符#{'${kakfa.topics}'}来进行参数注入 @KafkaListener(topics = ...

  6. Samba服务配置文件中涉及到的配置命令(转)

    Samba服务配置文件中涉及到的配置命令(转) 在下面所列出的,等号后没有内容的是系统没有设置或为空的(本人理解) coding system = # client code page = 936 # ...

  7. Spring Boot 配置文件中的花样,看这一篇足矣!

    点击蓝色"程序猿DD"关注我哟 加个"星标",不忘签到哦 关注我,回复口令获取可获取独家整理的学习资料: - 001 :领取<Spring Boot基础教 ...

  8. druid jar包_使用druid实现Spring boot配置文件中数据库密码密文存储

    通常在编写代码的时候,数据库的用户名和密码以明文的方法写到配置文件中,系统运维为了保证一定的安全性,要求我们在配置文件中使用密文的方式存储,本文主要介绍使用druid实现数据库密码密文显示的方法. 一 ...

  9. Spring MVC配置文件的三个常用配置详解

    2019独角兽企业重金招聘Python工程师标准>>> Spring MVC项目中通常会有二个配置文件,sprng-servlet.xml和applicationContext.xm ...

  10. 聊聊 Spring 核心特性中的数据绑定 (DataBinder)

    前面的话 Spring 的核心特性包括 IOC 容器.事件.资源管理.国际化.校验.数据绑定.类型转换.EL 表达式.AOP.其他特性可以轻易的在网络上找到很多资料,而数据绑定这个特性即便在 Spri ...

最新文章

  1. 【网络流24题】I、 方格取数问题(二分图的最大独立集/最小割)
  2. 视频插帧--Video Frame Interpolation via Adaptive Convolution
  3. jquery 选择时间(小时)区间(四)
  4. ubuntu下移植QT基本流程
  5. 当一个程序员面临太多选择的时候
  6. CSS:基本概念、选择器、伪类伪元素
  7. 深入理解ES6之迭代器与生成器
  8. HTML 基础语言
  9. JavaScript 资源列表
  10. Java基础篇:如何嵌套try语句?
  11. 常用的php类、方法、函数 注释标记
  12. 如何借助表格优化直通车分时折扣
  13. 日企抛等离子淘汰论 专家称其不敌中国企业
  14. 数据库Clinvar简介
  15. 双Nmos管驱动电路
  16. iOS培训机构该如何选择之浅析
  17. Spring源码解读(一)——容器是如何初始化的
  18. Kymeta加入美国陆军装甲旅战斗队试点项目
  19. OMG,学它!java培训讲师面试技巧
  20. Rosetta score

热门文章

  1. 解决ppt复制到Word的图片导出PDF后出现黑线问题,word转PDF图片不清晰的问题,ppt转矢量图问题
  2. 不显示BOM清单的版本
  3. word排版一般步骤
  4. VS2015 无法打开包括文件string.h等
  5. String类的常用方法都有哪些?
  6. 检错码与纠错码,一码归一码
  7. linux系统chmod 755权限
  8. FreeCAD源码分析:Assembly3模块
  9. 模电摸索日记之《晶体管放大电路》
  10. 【STM32F429的DSP教程】第14章 DSP统计函数-最大值,最小值,平均值和功率