1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <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"
  3.  
    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"
  4.  
    xmlns:cache="http://www.springframework.org/schema/cache"
  5.  
    xsi:schemaLocation="
  6.  
    http://www.springframework.org/schema/context
  7.  
    http://www.springframework.org/schema/context/spring-context.xsd
  8.  
    http://www.springframework.org/schema/beans
  9.  
    http://www.springframework.org/schema/beans/spring-beans.xsd
  10.  
    http://www.springframework.org/schema/tx
  11.  
    http://www.springframework.org/schema/tx/spring-tx.xsd
  12.  
    http://www.springframework.org/schema/jdbc
  13.  
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
  14.  
    http://www.springframework.org/schema/cache
  15.  
    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
  16.  
    http://www.springframework.org/schema/aop
  17.  
    http://www.springframework.org/schema/aop/spring-aop.xsd
  18.  
    http://www.springframework.org/schema/util
  19.  
    http://www.springframework.org/schema/util/spring-util.xsd">
  20.  
     
  21.  
    <!-- 自动扫描web包 ,将带有注解的类 纳入spring容器管理 -->
  22.  
    <context:component-scan base-package="com.eduoinfo.finances.bank.web"></context:component-scan>
  23.  
     
  24.  
    <!-- 引入jdbc配置文件 -->
  25.  
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  26.  
    <property name="locations">
  27.  
    <list>
  28.  
    <value>classpath*:jdbc.properties</value>
  29.  
    </list>
  30.  
    </property>
  31.  
    </bean>
  32.  
     
  33.  
    <!-- dataSource 配置 -->
  34.  
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  35.  
    <!-- 基本属性 url、user、password -->
  36.  
    <property name="url" value="${jdbc.url}" />
  37.  
    <property name="username" value="${jdbc.username}" />
  38.  
    <property name="password" value="${jdbc.password}" />
  39.  
     
  40.  
    <!-- 配置初始化大小、最小、最大 -->
  41.  
    <property name="initialSize" value="1" />
  42.  
    <property name="minIdle" value="1" />
  43.  
    <property name="maxActive" value="20" />
  44.  
     
  45.  
    <!-- 配置获取连接等待超时的时间 -->
  46.  
    <property name="maxWait" value="60000" />
  47.  
     
  48.  
    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  49.  
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
  50.  
     
  51.  
    <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  52.  
    <property name="minEvictableIdleTimeMillis" value="300000" />
  53.  
     
  54.  
    <property name="validationQuery" value="SELECT 'x'" />
  55.  
    <property name="testWhileIdle" value="true" />
  56.  
    <property name="testOnBorrow" value="false" />
  57.  
    <property name="testOnReturn" value="false" />
  58.  
     
  59.  
    <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
  60.  
    <property name="poolPreparedStatements" value="false" />
  61.  
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
  62.  
     
  63.  
    <!-- 配置监控统计拦截的filters -->
  64.  
    <property name="filters" value="stat" />
  65.  
    </bean>
  66.  
     
  67.  
    <!-- mybatis文件配置,扫描所有mapper文件 -->
  68.  
    <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" />
  69.  
     
  70.  
    <!-- spring与mybatis整合配置,扫描所有dao -->
  71.  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.eduoinfo.finances.bank.web.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" />
  72.  
     
  73.  
    <!-- 对dataSource 数据源进行事务管理 -->
  74.  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
  75.  
     
  76.  
    <!-- 配置使Spring采用CGLIB代理 -->
  77.  
    <aop:aspectj-autoproxy proxy-target-class="true" />
  78.  
     
  79.  
    <!-- 启用对事务注解的支持 -->
  80.  
    <tx:annotation-driven transaction-manager="transactionManager" />
  81.  
     
  82.  
    <!-- Cache配置 -->
  83.  
    <cache:annotation-driven cache-manager="cacheManager" />
  84.  
    <bean id="ehCacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" />
  85.  
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehCacheManagerFactory" />
  86.  
     
  87.  
    </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容器管理

在类上 ,使用以下注解,实现bean 的声明

@Component 泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

@Service 用于标注业务层组件

@Controller 用于标注控制层组件(如srping mvc的controller,struts中的action)

@Repository 用于标注数据访问组件,即DAO组件

示例:

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

}

------------------------------------------------------------------------------------------------------------------

在类的成员变量上,使用以下注解,实现属性的自动装配

@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;

转自https://blog.csdn.net/chungle2011/article/details/52523946

spring applicationContext.xml 配置文件 详解的更多相关文章

  1. Spring笔记--xml配置文件详解

    1:bean的基本属性配置: <!-- id是bean的标识符,必须唯一,如果没有配置id,name默认为标识符 如果配置了id,有配置了name,那么name为别名 name可以设置多个别名, ...

  2. Spring 2.5配置文件详解(转)

    http://book.51cto.com/art/201004/193743.htm 6.2.3  Spring 2.5配置文件详解 Spring配置文件是用于指导Spring工厂进行Bean生产. ...

  3. sqlMapConfig.xml配置文件详解

    sqlMapConfig.xml配置文件详解: Xml代码 Xml代码  <? xml version="1.0" encoding="UTF-8" ?& ...

  4. AndroidManifest.xml配置文件详解(转载)

     AndroidManifest.xml配置文件详解 2013-01-05 10:25:23 分类: Android平台 AndroidManifest.xml配置文件对于Android应用开发来说是 ...

  5. ApplicationContext.xml文件详解

    想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好).以至于有的初学者都不知道Spring配置文件的意思,就拿来用了.所以今天我给大家详 ...

  6. struts2.0中struts.xml配置文件详解

    先来展示一个配置文件 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration ...

  7. maven学习(一)setting.xml配置文件详解

    maven环境搭建: 1.官网下载zip包,解压至任意目录(如:E:\wly\apache-maven-3.2.5) 2.环境变量MAVEN_HOME(E:\wly\apache-maven-3.2. ...

  8. 1-1 struts2 基本配置 struts.xml配置文件详解

    详见http://www.cnblogs.com/dooor/p/5323716.html 一. struts2工作原理(网友总结,千遍一律) 1 客户端初始化一个指向Servlet容器(例如Tomc ...

  9. log4j.xml配置文件详解

    一 log4j.xml 配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:c ...

随机推荐

  1. (笔记)linux设备驱动--LED驱动

    linux设备驱动--LED驱动 最近正在学习设备驱动开发,因此打算写一个系列博客,即是对自己学习的一个总结,也是对自己的一个督促,有不对,不足,需要改正的地方还望大家指出,而且希望结识志同道合的朋友 ...

  2. Prolog学习:数独和八皇后问题

    上一篇简单介绍了下Prolog的一些基本概念,今天我们来利用这些基本概念解决两个问题:数独和八皇后问题. 数独 数独是一个很经典的游戏: 玩家需要根据n×n盘面上的已知数字,推理出所有剩余空格的数字, ...

  3. 部署基于Maven的war文件到Tomcat

    在本教程中,我们将学习如何使用Maven的Tomcat插件打包并部署一个WAR文件到Tomcat(Tomcat的6和7. 要用到工具: Maven 3 Tomcat 6.0.37 Tomcat 7.0 ...

  4. Python操作SQLServer示例(转)

    转自:http://www.cnblogs.com/lrzy/p/4346781.html 本文主要是Python操作SQLServer示例,包括执行查询及更新操作(写入中文). 需要注意的是:读取数 ...

  5. 分享一个MAC下绕开百度网盘限速下载的方法,三步操作永久生效

    相信大家都比较困惑,百度网盘客户端限速后一般只有几十K的下载速度,Windows有百度网盘破解版,但MAC的破解版似乎不存在,要提速的话,一般的做法是开超级会员(27元/月),身为程序员的我们,是不是 ...

  6. (实用)Ubuntu Linux静态IP网络配置

    记录备忘. 基于Ubuntu 14.04 LTS Server. 首先查看一下当前系统的网卡: $ sudo iconfig 比如这里我除了回环网路lo外,网络接口名为em1,下面就去给它配置网络. ...

  7. POJ 3481 Double Queue(STL)

    题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身 ...

  8. application.properties详解 --springBoot配置文件

    本文转载:http://blog.csdn.net/lpfsuperman/article/details/78287265###; # spring boot application.propert ...

  9. [mysql-Ver5.6.23] windows版my.ini配置

    基于utf8mb4比utf8多了种编码,能更好的支持emoji表情(http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.htm ...

  10. 浪漫程序员 HTML5爱心表白动画

    我们程序员在追求爱情方面也是非常浪漫的,下面是一位同学利用自己所学的HTML5知识自制的HTML5爱心表白动画,画面非常温馨甜蜜,这样的创意很容易打动女孩,如果你是单身的程序员,也赶紧来制作自己的爱心 ...