激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - 詳解spring applicationContext.xml 配置文件

詳解spring applicationContext.xml 配置文件

2020-08-02 12:00夢(mèng)想合伙人 Java教程

本篇文章主要介紹了詳解spring applicationContext.xml 配置文件 ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

applicationContext.xml 文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  xmlns:cache="http://www.springframework.org/schema/cache"
  xsi:schemaLocation="
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx.xsd
  http://www.springframework.org/schema/jdbc
  http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
  http://www.springframework.org/schema/cache
  http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop.xsd
  http://www.springframework.org/schema/util
  http://www.springframework.org/schema/util/spring-util.xsd">
 
  <!-- 自動(dòng)掃描web包 ,將帶有注解的類 納入spring容器管理 -->
  <context:component-scan base-package="com.eduoinfo.finances.bank.web"></context:component-scan>
 
  <!-- 引入jdbc配置文件 -->
  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
      <list>
        <value>classpath*:jdbc.properties</value>
      </list>
    </property>
  </bean>
 
  <!-- dataSource 配置 -->
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    <!-- 基本屬性 url、user、password -->
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
 
    <!-- 配置初始化大小、最小、最大 -->
    <property name="initialSize" value="1" />
    <property name="minIdle" value="1" />
    <property name="maxActive" value="20" />
 
    <!-- 配置獲取連接等待超時(shí)的時(shí)間 -->
    <property name="maxWait" value="60000" />
 
    <!-- 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉的空閑連接,單位是毫秒 -->
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
 
    <!-- 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒 -->
    <property name="minEvictableIdleTimeMillis" value="300000" />
 
    <property name="validationQuery" value="SELECT 'x'" />
    <property name="testWhileIdle" value="true" />
    <property name="testOnBorrow" value="false" />
    <property name="testOnReturn" value="false" />
 
    <!-- 打開(kāi)PSCache,并且指定每個(gè)連接上PSCache的大小 -->
    <property name="poolPreparedStatements" value="false" />
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
 
    <!-- 配置監(jiān)控統(tǒng)計(jì)攔截的filters -->
    <property name="filters" value="stat" />
  </bean>
 
  <!-- mybatis文件配置,掃描所有mapper文件 -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml" p:mapperLocations="classpath:com/eduoinfo/finances/bank/web/dao/*.xml" />
 
  <!-- spring與mybatis整合配置,掃描所有dao -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.eduoinfo.finances.bank.web.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
 
  <!-- 對(duì)dataSource 數(shù)據(jù)源進(jìn)行事務(wù)管理 -->
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
 
  <!-- 配置使Spring采用CGLIB代理 -->
  <aop:aspectj-autoproxy proxy-target-class="true" />
 
  <!-- 啟用對(duì)事務(wù)注解的支持 -->
  <tx:annotation-driven transaction-manager="transactionManager" />
 
  <!-- Cache配置 -->
  <cache:annotation-driven cache-manager="cacheManager" />
  <bean id="ehCacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" />
  <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehCacheManagerFactory" />
 
</beans>

1、<context:component-scan base-package="com.eduoinfo.finances.bank.web"></context:component-scan> 作用Spring 容器初始化的時(shí)候,會(huì)掃描 com.eduoinfo.finances.bank.web下 標(biāo)有 (@Component,@Service,@Controller,@Repository) 注解的 類 納入spring容器管理

在類上 ,使用以下注解,實(shí)現(xiàn)bean 的聲明

@Component 泛指組件,當(dāng)組件不好歸類的時(shí)候,我們可以使用這個(gè)注解進(jìn)行標(biāo)注。

@Service 用于標(biāo)注業(yè)務(wù)層組件

@Controller 用于標(biāo)注控制層組件(如srping mvc的controller,struts中的action)

@Repository 用于標(biāo)注數(shù)據(jù)訪問(wèn)組件,即DAO組件

示例:

?
1
2
3
4
5
@Controller
@RequestMapping(value = "/test")
public class TestController {
 
}

在類的成員變量上,使用以下注解,實(shí)現(xiàn)屬性的自動(dòng)裝配

@Autowired : 按類 的 類型進(jìn)行裝配

@Resource (推薦) :

1 如果同時(shí)指定了name和type,則從spring上下文中找到唯一匹配的bean進(jìn)行裝配,找不到則拋出異常

2. 如果指定了name,則從上下文中查找名稱(id)匹配的bean進(jìn)行裝配,找不到則拋出異常 

3.如果指定了type,則從上下文中找到類型匹配的唯一bean進(jìn)行裝配,找不到或者找到多個(gè),都會(huì)拋出異常

4.如果既沒(méi)有指定name,又沒(méi)有指定type,則自動(dòng)按照byName方式進(jìn)行裝配;如果沒(méi)有匹配,則回退為一個(gè)原始類型進(jìn)行匹配,如果匹配則自動(dòng)裝配;

@Resource注解在字段上,這樣就不用寫setter方法了,并且這個(gè)注解是屬于J2EE的,減少了與spring的耦合。

示例:

?
1
2
@Resource
private TestServiceImpl testServiceImpl;

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/zoutongyuan/article/details/27073683

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久免费视频1 | 99精品视频久久精品视频 | 在线观看日韩中文字幕 | 日本一区二区久久 | 国产一区二区视频在线播放 | 成人免费在线网 | 一区二区三区日韩在线 | 久久美女色视频 | 免费a级观看 | 久久成人在线观看 | 久久经典国产视频 | 99精品视频在线 | 久久久久久麻豆 | 狠狠操夜夜爱 | 51色视频 | 中文字幕天堂在线 | 毛片在线免费播放 | 蜜桃网在线 | hdhdhd79xxxxх | 99精品国产小情侣高潮露脸在线 | 欧美成人免费一级 | 成人羞羞在线观看网站 | 欧美日韩免费看 | 国产女同疯狂激烈互摸 | 久久性生活免费视频 | 国产精品一区二区三区在线 | 成人一级毛片 | 久久精品欧美一区二区三区不卡 | 美国一级毛片片aa久久综合 | 一级免费黄色免费片 | 欧美性受xxxxxx黑人xyx性爽 | 欧洲色阁中文字幕 | 91九色精品国产 | 91色一区二区三区 | 激情五月少妇a | 嗯~啊~用力~高h | 亚洲成人在线免费 | 国产成人在线视频 | 欧美成人精品欧美一级乱黄 | 第一区免费在线观看 | 草逼一区|