日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

druiddatasource配置_Spring核心配置文件详解

發(fā)布時間:2023/12/10 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 druiddatasource配置_Spring核心配置文件详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

點擊藍字“程序員考拉”歡迎關注!

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

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

<context-param>
????????<param-name>contextConfigLocationparam-name>
????????<param-value>classpath:spring/applicationContext*.xmlparam-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):然后加載在核心配置文件中加載數據庫文件.

t:property-placeholder location="classpath:resource/db.properties"?/>

(3):配置數據庫連接池,配置類可以用BasicDatasource,也可以用阿里巴巴的配置核心類 DruidDataSource。

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

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

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

? ? ?和hibernate的一個整合。

"sessionFactory"?class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property?name="dataSource"><ref?bean="dataSource"/>property>bean>

和mybatis的一個整合.


????<bean?id="sqlSessionFactory"?class="org.mybatis.spring.SqlSessionFactoryBean">
????????
????????<property?name="dataSource"?ref="dataSource"?/>
????????
????????<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層。

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

關于注解注入的配置

(6):在進行配置的時候所需要引入的命名空間。

"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.xsd
????http://www.springframework.org/schema/context http://www.springframework.org/s ... ing-context-4.0.xsd
????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
????http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

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

原文鏈接:https://blog.csdn.net/hyd130/article/details/73480943

如果感覺推送內容不錯,不妨右下角點個在看,感謝支持!

總結

以上是生活随笔為你收集整理的druiddatasource配置_Spring核心配置文件详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。