关于spring核心配置文件中的各项主要配置

2023-05-16

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


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

   
[html] view plain copy
  1. <context-param>  
  2.        <param-name>contextConfigLocation</param-name>  
  3.        <param-value>classpath:spring/applicationContext*.xml</param-value>  
  4.    </context-param>  





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

[html] view plain copy
  1. jdbc.driver=com.mysql.jdbc.Driver  
  2. jdbc.url=jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=utf-8  
  3. jdbc.username=root  
  4. jdbc.password=123456  




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

[html] view plain copy
  1. <context:property-placeholder location="classpath:resource/db.properties" />  




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

[html] view plain copy
  1. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  
  2.         destroy-method="close">  
  3.         <property name="url" value="${jdbc.url}" />  
  4.         <property name="username" value="${jdbc.username}" />  
  5.         <property name="password" value="${jdbc.password}" />  
  6.         <property name="driverClassName" value="${jdbc.driver}" />  
  7.         <property name="maxActive" value="10" />  
  8.         <property name="minIdle" value="5" />  
  9.     </bean>  




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

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

[html] view plain copy
  1. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  2.           <!-- 与dataSource -->  
  3.           <property name="dataSource">  
  4.               <ref bean="dataSource"/>  
  5.          </property>  
  6. </bean>  




  和mybatis的一个整合.

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



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

[html] view plain copy
  1. !-- 事务管理器 -->  
  2.     <bean id="transactionManager"  
  3.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  4.         <!-- 数据源 -->  
  5.         <property name="dataSource" ref="dataSource" />  
  6.     </bean>  




配置通知。

[html] view plain copy
  1. <!-- 通知 -->  
  2.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  3.         <tx:attributes>  
  4.             <!-- 传播行为 -->  
  5.             <tx:method name="save*" propagation="REQUIRED" />  
  6.             <tx:method name="insert*" propagation="REQUIRED" />  
  7.             <tx:method name="add*" propagation="REQUIRED" />  
  8.             <tx:method name="create*" propagation="REQUIRED" />  
  9.             <tx:method name="delete*" propagation="REQUIRED" />  
  10.             <tx:method name="update*" propagation="REQUIRED" />  
  11.             <tx:method name="find*" propagation="SUPPORTS" read-only="true" />  
  12.             <tx:method name="select*" propagation="SUPPORTS" read-only="true" />  
  13.             <tx:method name="get*" propagation="SUPPORTS" read-only="true" />  
  14.         </tx:attributes>  
  15.     </tx:advice>  




关于切面的配置。

[html] view plain copy
  1. <!-- 切面 -->  
  2.     <aop:config>  
  3.         <aop:advisor advice-ref="txAdvice"  
  4.             pointcut="execution(* com.store.service.*.*(..))" />  
  5.     </aop:config>  




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

[html] view plain copy
  1. <context:component-scan base-package="com.xiaoao.service"/>   




关于注解注入的配置

[html] view plain copy
  1. <mvc:annotation-driven />  




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

[html] view plain copy
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.     xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"  
  3.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
  6.     http://www.springframework.org/schema/context http://www.springframework.org/s ... ing-context-4.0.xsd  
  7.     http://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.xsd  
  8.     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">  




   jar包导入的话,可以使用maven管理,非常方便。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

关于spring核心配置文件中的各项主要配置 的相关文章

随机推荐

  • android studio unresolved reference:xx问题解决方案汇总

    android studio unresolved reference xff1a xx问题解决方案汇总 目录第一种 xff0c 重启法 xff0c clean 43 invalidate caches restart第二种 xff0c g
  • Router 选择

    Connected Dominating Set Example of a Connected Dominating Set Router 必须形成一个 CDS xff08 Connected Dominating Set xff0c 连接
  • devtool: unset _PYTHON_SYSCONFIGDATA_NAME

    问题 在 Ubuntu 20 04 1 LTS 上进行编译Yocto时报错 xff0c 出现如下错误 xff1a bb data smart ExpansionError Failure expanding variable SRCPV e
  • VsCode 配置PySide6及测试

    目录 VSCode插件安装安装Python插件安装PySide6插件 PySide6安装PySide6配置VSCode创建UI文件 在这里插入图片描述 https img blog csdnimg cn cbf7cd76d7d84048ab
  • Ubuntu 14.04 Desktop的Raid1安装总结

    Ubuntu 14 04 Desktop的Raid1安装总结 安装基于Ubuntu14 04 Desktop的Raid1 由于采用UEFI GPT方式作为系统启动方式 xff0c 在安装过程中出现了很多异常情况 本文记录安装的过程 安装步骤
  • sem_wait sem_post信号量操作进本函数

    sem wait sem post 信号量的数据类型为结构sem t xff0c 它本质上是一个长整型的数 函数sem init xff08 xff09 用来初始化一个信号量 它的原型为 xff1a extern int sem init
  • 常见gcc编译警告整理(开始)

    1 warning no newline at end of file 在文件最后一行加上回车键 解释 xff1a 在 Rationale for the C99 standard 一文中 xff0c 有C99的相关信息 xff1a A b
  • 对于结构体变量赋值的误区

    以前在使用结构体时没有在结构体变量之间直接赋值 xff0c 今天同事在查看别人的代码时 xff0c 发现有两个结构体变量直接赋值的语句当时感觉这个语句不对 xff0c 认为在一个结构体里边 xff0c 既有一般的无符号整形与数组 xff0c
  • 线程同步(互斥锁与信号量的作用与区别)

    信号量用在多线程多任务同步的 xff0c 一个线程完成了某一个动作就通过信号量告诉别的线程 xff0c 别的线程再进行某些动作 xff08 大家都在semtake的时候 xff0c 就阻塞在 哪里 xff09 而互斥锁是用在多线程多任务互斥
  • 误解程序运行(从单片机到开始)

    误解程序运行 从单片机到开始 关于程序的执行 xff0c 以前想的不多 xff0c 没有意识到一个程序在运行时 xff0c 从哪里读指令 xff0c 数据又写在哪里 最近在看CSAPP时这个念头经常在脑袋中晃荡 从单片机上知道 xff0c
  • ssh配置key后提示Server refused our key

    文章目录 1 确认问题2 解决问题 1 确认问题 参考 xff1a Putty Getting Server refused our key Error 为了确认ssh具体的错误 xff0c 可以去 etc ssh sshd config中
  • Out-of-Bounds Memory References and Buffer Overflow

    callee pushl edp save edp on stack movl esp edp pushl ebx save ebx subl 20 esp popl ebx restore ebx popl edp restore
  • 电子信息工程四年学习之思

    毕业后 xff0c 回顾四年学习历程发现 xff0c 当时以为的明白 xff0c 到现在都是那时的不明白 或许是自己的经历 xff08 参加比赛比较多 xff09 导致了现在的反思 但是 xff0c 回顾那个时候的课程设置 xff0c 却都
  • 将要到来的三大技术革命与联系

    http www csdn net article 2013 02 14 2814128 2013大数据 http www csdn net article 2013 02 15 2814135 bigdata is coming 大数据
  • Keil的常见编译警告

    1 warning 767 D conversion from pointer to smaller integer 解释 xff1a 将指针转换为较小的整数 影响 xff1a 可能造成的影响 xff1a 容易引起数据截断 xff0c 造成
  • 《大数据时代》之后

    现在想想也不记得当时是怎么找到 大数据时代 这本书的 xff0c 好像是在查找数据库方面的书 xff0c 看到亚马逊推荐的书里有这本 xff0c 发现最近才出版的就买一本回来看看 然而这个过程中 xff0c 其实自己已经得到了大数据带来的影
  • 《代码大全》笔记

    最近将去年毕业时 xff0c 大神推荐的 代码大全 看完了 xff08 已经过去一年了 xff0c 要十分感谢推荐 xff0c 还有凤林兄的 深入理解计算机系统 xff09 零零碎碎的时间 xff0c 发现很多东西虽然在书中标记了 xff0
  • 《编程精粹》思之代码与产品

    之前眼中有代码无产品 xff0c 现在眼中有产品有代码 xff0c 什么时候能做到有产品无代码 xff1f 还需要努力 刚开始实习的时候 xff0c 总喜欢在程序中使用 p 43 1 61 而不是p 1 来给入参 xff0c 甚至于用来给定
  • 杂记:pyinstaller 常用参数和可执行文件启动目录的注意事项

    pyinstaller 常用参数 所谓的常用参数 xff0c 就是指 xff1a 不想看详细帮助不关心版本 一来 pip list 就能知道版本 xff0c 不需要专门记 pyinstaller 的参数 二来能用就行 达到生成 exe 的目
  • 关于spring核心配置文件中的各项主要配置

    1 xff1a spring的核心配置文件中的各种配置 spring的核心配置文件的名字 叫做 applicationContext xml xff0c 后期也可以通过配置文件中的配置修改名称 xff0c 在web xml中进行如下配置 x