最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解spring applicationContext.xml 配置文件

 更新時間:2017年02月03日 14:09:00   作者:夢想合伙人  
本篇文章主要介紹了詳解spring applicationContext.xml 配置文件 ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

applicationContext.xml 文件

<?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"> 
 
  <!-- 自動掃描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" /> 
 
    <!-- 配置獲取連接等待超時的時間 --> 
    <property name="maxWait" value="60000" /> 
 
    <!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒 --> 
    <property name="timeBetweenEvictionRunsMillis" value="60000" /> 
 
    <!-- 配置一個連接在池中最小生存的時間,單位是毫秒 --> 
    <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" /> 
 
    <!-- 打開PSCache,并且指定每個連接上PSCache的大小 --> 
    <property name="poolPreparedStatements" value="false" /> 
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> 
 
    <!-- 配置監(jiān)控統(tǒng)計攔截的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" /> 
 
  <!-- 對dataSource 數(shù)據(jù)源進行事務管理 --> 
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" /> 
 
  <!-- 配置使Spring采用CGLIB代理 --> 
  <aop:aspectj-autoproxy proxy-target-class="true" /> 
 
  <!-- 啟用對事務注解的支持 --> 
  <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 容器初始化的時候,會掃描 com.eduoinfo.finances.bank.web下 標有 (@Component,@Service,@Controller,@Repository) 注解的 類 納入spring容器管理

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

@Component 泛指組件,當組件不好歸類的時候,我們可以使用這個注解進行標注。

@Service 用于標注業(yè)務層組件

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

@Repository 用于標注數(shù)據(jù)訪問組件,即DAO組件

示例:

@Controller
@RequestMapping(value = "/test")
public class TestController {

}

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

@Autowired : 按類 的 類型進行裝配

@Resource (推薦) :

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

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

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

4.如果既沒有指定name,又沒有指定type,則自動按照byName方式進行裝配;如果沒有匹配,則回退為一個原始類型進行匹配,如果匹配則自動裝配;

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

示例:

@Resource
private TestServiceImpl testServiceImpl;

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Spring源碼解析容器初始化構造方法

    Spring源碼解析容器初始化構造方法

    這篇文章主要介紹了Spring源碼解析容器初始化構造方法,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • 實例詳解Spring Boot實戰(zhàn)之Redis緩存登錄驗證碼

    實例詳解Spring Boot實戰(zhàn)之Redis緩存登錄驗證碼

    本章簡單介紹redis的配置及使用方法,本文示例代碼在前面代碼的基礎上進行修改添加,實現(xiàn)了使用redis進行緩存驗證碼,以及校驗驗證碼的過程。感興趣的的朋友一起看看吧
    2017-08-08
  • javaSE基礎java自定義注解原理分析

    javaSE基礎java自定義注解原理分析

    這篇文章主要介紹了javaSE基礎對java自定義注解原理分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多度進步,早日升職加薪
    2021-10-10
  • spring cloud 阿波羅 apollo 本地開發(fā)環(huán)境搭建過程

    spring cloud 阿波羅 apollo 本地開發(fā)環(huán)境搭建過程

    Apollo(阿波羅)是攜程框架部門研發(fā)的配置管理平臺,能夠集中化管理應用不同環(huán)境、不同集群的配置,配置修改后能夠實時推送到應用端,并且具備規(guī)范的權限、流程治理等特性
    2018-01-01
  • 超詳細講解Java秒殺項目用戶驗證模塊的實現(xiàn)

    超詳細講解Java秒殺項目用戶驗證模塊的實現(xiàn)

    這是一個主要使用java開發(fā)的秒殺系統(tǒng),項目比較大,所以本篇只實現(xiàn)了用戶驗證模塊,代碼非常詳盡,感興趣的朋友快來看看
    2022-03-03
  • Java中StringBuffer和StringBuilder區(qū)別

    Java中StringBuffer和StringBuilder區(qū)別

    這篇文章主要介紹了Java中StringBuffer和StringBuilder區(qū)別,本文只介紹了它們之間的核心區(qū)別,需要的朋友可以參考下
    2015-06-06
  • Mybatis 返回值類型和參數(shù)傳遞的配置方法

    Mybatis 返回值類型和參數(shù)傳遞的配置方法

    在 MyBatis 中,返回值類型和參數(shù)傳遞是 Mapper 接口中至關重要的兩個方面,正確理解和使用它們可以幫助我們高效、準確地進行數(shù)據(jù)庫操作,接下來通過本文給大家介紹Mybatis 返回值類型和參數(shù)傳遞的配置方法,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • Java原子變量類原理及實例解析

    Java原子變量類原理及實例解析

    這篇文章主要介紹了Java原子變量類原理及實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-12-12
  • hadoop的wordcount實例代碼

    hadoop的wordcount實例代碼

    這篇文章主要介紹了hadoop的wordcount實例代碼,分享了相關代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • Java8中 LocalDate和java.sql.Date的相互轉換操作

    Java8中 LocalDate和java.sql.Date的相互轉換操作

    這篇文章主要介紹了Java8中 LocalDate和java.sql.Date的相互轉換操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12

最新評論

河南省| 泗洪县| 金沙县| 泰州市| 盈江县| 沾化县| 秦皇岛市| 寻乌县| 安宁市| 桂平市| 靖边县| 岳西县| 七台河市| 大足县| 乐至县| 乌拉特中旗| 郓城县| 五峰| 登封市| 德保县| 黄龙县| 辽阳县| 金门县| 布尔津县| 米脂县| 合水县| 郸城县| 新蔡县| 怀远县| 新民市| 哈密市| 阿坝县| 洛浦县| 汤原县| 仲巴县| 丹巴县| 桑日县| 昭苏县| 平凉市| 内乡县| 台南市|