spring注解注入示例详解-(二).docVIP

  • 4
  • 0
  • 约1.09万字
  • 约 11页
  • 2016-01-02 发布于山西
  • 举报
spring注解注入示例详解-(二)

spring注解注入示例详解 ——我的spring注解注入学习心得 重庆正大软件职业技术学院 网络技术系:杨讯 本文是我在业余时间学习spring注解注入之后的整理总结,希望能给对spring注入技术感兴趣和正在学习spring注入的同学们一些帮助。文中的内容都是我自己的摸索总结,当中难免会有偏差和错误,希望spring达人能够及时给予指正,本人感激不尽。下面是我的联系方式,希望大家能够多多交流。 email:Y_X_82@163.com 百度账号:Y_X_82 spring注解注入示例详解-(二) 今天我们的笔记给大家分享分享我在spring的注解注入机制中配置Hibernate的过程。Hibernate作为SSH架构中重要成员,在后台代码和数据库的交互当中起着至关重要的作用,在上一篇文章中,我们使用注解注入的方式配置了表现层的controller,不知道大家有没有发现,controller的配置成功让spring彻底摆脱了在表现层对struts的依赖。今天我们配置的Hibernate部分是否也能让spring更加独立呢? 1.1 配置Hibernate属性 我们首先要说明,本次我们使用的数据库是mysql,数据库服务是装在本地3306端口,数据库名称是javassdb,用户名是root,密码是123456。 1.1.1 perties文件定义数据库连接池属性 为了让spring配置文件相对独立,尽量少受其他因素影响,我们首先在WEB-INF目录下新建一个perties文件来存放数据库连接池的相关配置,当然,你也可以直接把这些配置写进spring的配置文件中: hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.hbm2ddl.auto=none hibernate.show_sql=false hibernate.query.substitutions=true 1, false 0 hibernate.default_batch_fetch_size=16 hibernate.max_fetch_depth=2 hibernate.bytecode.use_reflection_optimizer=true hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=org.hibernate.cache.EhCacheRegionFactory net.sf.ehcache.configurationResourceName=/ehcache_hibernate.xml hibernate.cache.use_structured_entries=true hibernate.generate_statistics=true connection.driver_class=com.mysql.jdbc.Driver connection.url=jdbc:mysql://localhost:3306/javassdb?useUnicode=trueamp;characterEncoding=UTF8 connection.username=root connection.password=123456 proxool.maximum.connection.count=40 proxool.minimum.connection.count=5 proxool.statistics=1m,15m,1h,1d proxool.simultaneous.build.throttle=30 接下来我们开始对spring配置文件进行配置。 spring配置文件中的Hibernate配置 配置属性文件链接 bean id=propertyConfigurer class=org.springframework.beans.factory.config.PropertyPlaceholderConfigurer property name=locations list value/WEB-INF/perties/value /list /property /bean 这个配置添加了之后,我们就可以在spring配置文件中用${****}来引用perties文件的设置 DataSource配置 bean id=dataSource class=xool.Pro

文档评论(0)

1亿VIP精品文档

相关文档