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>

在类上 ,使用以下注解,实现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;

http://blog.csdn.net/zoutongyuan/article/details/27073683

spring applicationContext.xml 文件的更多相关文章

  1. spring applicationContext.xml文件移到resources目录下

    SpringMVC的框架默认目录结构 修改后的目录结构及web.xml 同时在pom里的配置:将resources目录打包到web-inf/classes目录下<resources>   ...

  2. Spring配置文件详解 - applicationContext.xml文件路径

    spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...

  3. Spring配置文件详解 – applicationContext.xml文件路径

    Spring配置文件详解 – applicationContext.xml文件路径 Java编程                 spring的配置文件applicationContext.xml的默 ...

  4. Spring中加载ApplicationContext.xml文件的方式

    Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...

  5. Spring的applicationContext.xml文件

    以下是详解Spring的applicationContext.xml文件代码:<!-- 头文件,主要注意一下编码 --><?xml version="1.0" e ...

  6. 当你的Spring IOC 容器(即applicationContext.xml文件)忘记配到web.xml 文件中时

    当你的Spring IOC 容器忘记配到web.xml 文件中时,启动服务器就会报错. 部分错误如下: Caused by: org.springframework.beans.factory.NoS ...

  7. Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

    Spring框架找不到 applicationContext.xml文件,可能是由于applicationContext.xml文件的路径没有放在根目录下造成的

  8. Spring MVC框架下在java代码中访问applicationContext.xml文件中配置的文件(可以用于读取配置文件内容)

    <bean id="propertyConfigurer" class="com.****.framework.core.SpringPropertiesUtil& ...

  9. spring将service添加事务管理,在applicationContext.xml文件中的设置

    在applicationContext.xml文件中的设置为: <beans> <bean id="sessionFactory" class="org ...

随机推荐

  1. Django web 开发指南 no such table:

    在学习django web开发指南时,发布新博客点击save后会有error提示:no such table balabalabala... 百度了一下说重新运行manage.py syncdb 就可 ...

  2. mysql-5.5.25-winx64在win7 x64 免安装配置

    os:win7 x64 mysql:mysql-5.5.25-winx64 将mysql-5.5.25-winx64.zip 解压缩到F:\mysql-5.5.25-winx64 目录下: 1.将my ...

  3. Mac双系统切换

    苹果系统和WIN7系统  切换和使用说明 先按住“alt(opfion)”不放手,然后在按开机键,会进入选择页面,选择win8 会进入 windos页面 ,选择MACintos h HD(Mac)会进 ...

  4. 30年的Hello world

    30 年的 Hello world 转载自:http://www.admin10000.com/document/2398.html 最近我在7月4日这一天所在的那周休假了.休假期间,我利用大把的时间 ...

  5. A simple test

        博士生课程报告       视觉信息检索技术                 博 士 生:施 智 平 指导老师:史忠植 研究员       中国科学院计算技术研究所   2005年1月   目 ...

  6. *string++优先级的问题

    这个东西困扰了我几天,关于优先级问题确实是个恼人的东西,为了这个专门翻了C语言课本,得知 所有一目运算符都是第二级优先级 结合性是从右到左 那么*string++应该就是*(string++),也就是 ...

  7. nginx优化 突破十万并发(转)

    一.一般来说nginx 配置文件中对优化比较有作用的为以下几项: 1. worker_processes 8; nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计 ...

  8. php获取html checkbox的值。

    一个小错误,搞了好久: <label><input class="short" type="checkbox" id="is_onl ...

  9. redis pub/sub 发布订阅

    Redis的列表数据结构有blpop和brpop命令,能从列表里返回且删除第一个(或最后一个)元素,或者被堵塞,直到有一个元素可供操作.这可以用来实现一个简单的队列.(参考:http://www.cn ...

  10. 《深入理解linux内核架构》第二章 进程管理和调度

    2.1进程优先级 进程优先级 硬实时进程 软实时进程 抢占式多任务处理 2.2进程生命周期 用户太切换到核心态的办法 系统调用 中断 抢占调度模型优先级普通进程<系统调用<中断 普通进程可 ...