spring 中application-context.xml所做内容
1、Spring 作为容器框架连接数据库使用 hibernate 而hibernate连接交与Spring 管理 装载组建如下
使用com.mchange.v2.c3p0.ComboPooledDataSource实例 (统称c3p0)
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true"/>
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
<property name="minPoolSize" value="${cpool.minPoolSize}"/>
<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>
2 、hibernate对数据库的操作注入dataSource 使用org.springframework.orm.hibernate3.LocalSessionFactoryBean实例
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations">
<list>
<value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value>
<value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.query.substitutions=true 1, false 0
hibernate.jdbc.batch_size=20
hibernate.cache.use_query_cache=true
</value>
</property>
<property name="entityInterceptor">
<ref local="treeInterceptor"/>
</property>
<property name="cacheProvider">
<ref local="cacheProvider"/>
</property>
<property name="lobHandler">
<ref bean="lobHandler" />
</property>
</bean>
3、hibernate操作数据库事务管理 注入sessionFactroy 使用org.springframework.orm.hibernate3.HibernateTransactionManager实例
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />(使用annotation定义事务)
4、如何代码需要注解引导还需
<context:annotation-config/>
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 组件扫描策略-->
<context:component-scan base-package="com.xyz.callcenter" />
5、可能还需国际化配置
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="cacheSeconds" value="-1"/>
<property name="basenames">
<list>
<value>/WEB-INF/languages/jeecms_front/messages</value>
<value>/WEB-INF/languages/jeecms_tpl/messages</value>
<value>/WEB-INF/languages/fck/messages</value>
</list>
</property>
</bean>
web.xml 所做内容
web.xml作为项目的起始容器主要能使配置的框架运作起来
如listener、filter 、 servlet
1、所需加载spring的xml文件(Spring ApplicationContext配置文件的路径供用于后面的Spring Context Loader)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/application-context.xml
</param-value>
</context-param>
2、项目中文转码问题过滤
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
3、hibernate懒加载配置(这里使用spinrg提供的jar 另外两种分别是代码设置,和hibernate 文件属性设置lazy="false" )
<filter>
<filter-name>osivFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
4、启动Spring配置信息(这里主要读取配置的spring的xml)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
5、如果web框架使用struts则在配置
<filter>
<!-- 定义核心filter的名字 -->
<filter-name>struts2</filter-name>
<!-- 定义核心filter的实现类 -->
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<!-- FilterDispatcher用来初始化struts2并且处理所有的web请求 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<!--默认拦截以.action结尾的请求 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
相关推荐
spring容器启动和关闭时事件监听;spring容器启动和关闭时事件监听;spring容器启动和关闭时事件监听
使用spring的Ioc容器组装各种组件总结
(完整版)基于SpringCloud微服务系统设计方案.docx(完整版)基于SpringCloud微服务系统设计方案.docx(完整版)基于SpringCloud微服务系统设计方案.docx(完整版)基于SpringCloud微服务系统设计方案.docx(完整版)基于...
(完整版)基于SpringCloud微服务系统设计方案.pdf(完整版)基于SpringCloud微服务系统设计方案.pdf(完整版)基于SpringCloud微服务系统设计方案.pdf(完整版)基于SpringCloud微服务系统设计方案.pdf(完整版)基于Spring...
基于spring cloud 和vue全家桶的开源电商源码基于spring cloud 和vue全家桶的开源电商源码基于spring cloud 和vue全家桶的开源电商源码基于spring cloud 和vue全家桶的开源电商源码基于spring cloud 和vue全家桶的...
基于spring boot餐厅管理系统源码 基于spring boot餐厅管理系统源码 基于spring boot餐厅管理系统源码 基于spring boot餐厅管理系统源码 基于spring boot餐厅管理系统源码 基于spring boot餐厅管理系统源码 ...
基于SpringCloud的在线学习测评系统源码 基于SpringCloud的在线学习测评系统源码 基于SpringCloud的在线学习测评系统源码 基于SpringCloud的在线学习测评系统源码 基于SpringCloud的在线学习测评系统源码 ...
Spring容器 .ppt Spring容器 .ppt
基于 Spring Cloud Hoxton 、Spring Boot 2.2、 OAuth2 的RBAC权限管理系统 基于数据驱动视图的理念封装 Ant Design Vue,即使没有 vue 的使用经验也能快速上手 提供 lambda 、stream api 、webflux 的生产实践 ...
基于SpringCloud的快递驿站系统源码 基于SpringCloud的快递驿站系统源码 基于SpringCloud的快递驿站系统源码 基于SpringCloud的快递驿站系统源码 基于SpringCloud的快递驿站系统源码 基于SpringCloud的...
在线教育平台服务端基于Spring Boot构建,采用Spring Cloud微服务框架。 持久层:MySQL、MongoDB、Redis、ElasticSearch 数据访问层:使用Spring Data JPA 、Mybatis、Spring Data Mongodb等 业务层:Spring IOC、...
基于SpringCloud的趋势投资分析系统 基于SpringCloud的趋势投资分析系统 基于SpringCloud的趋势投资分析系统 基于SpringCloud的趋势投资分析系统 基于SpringCloud的趋势投资分析系统 基于SpringCloud的趋势投资...
在非spring注解类中使用spring容器中的bean_普通类中使用yml配置文件中的配置信息,在大数据采集项目中用到的,已经测试过了
Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+...
- 基于 Spring Cloud 2021 、Spring Boot 2.7、 OAuth2 的 RBAC **权限管理系统** - 基于数据驱动视图的理念封装 element-ui,即使没有 vue 的使用经验也能快速上手 - 提供对常见容器化支持 Docker、Kubernetes、...
基于Spring cloud + vue 的前后端分离社团管理系统,因学校没有成熟的社团管理系统,一为满足学校需求, 其次开源的社团管理项目,多为mvc ssm框架 很少有前后端分离的微服务框架,为了科技的发展, 更好学习解决高...
他们都可代表Spring容器,Spring容器是生成Bean实例的工厂,并且管理容器中的Bean。 Bean是Spring管理的基本单位,在基于Spring的Java EE应用中,所有的组件都被当成Bean处理,包括数据源、Hibernate的...
java毕业设计——基于spring boot的音乐播放网站设计与实现(源码+数据库).zip java毕业设计——基于spring boot的音乐播放网站设计与实现(源码+数据库).zip java毕业设计——基于spring boot的音乐播放网站设计与...
基于 Spring Boot + MySQL 开发的博客系统源码 基于 Spring Boot + MySQL 开发的博客系统源码 基于 Spring Boot + MySQL 开发的博客系统源码 基于 Spring Boot + MySQL 开发的博客系统源码 基于 Spring ...
基于SpringCloud的秒杀项目,集合了zookeeper、redis、支付宝支付、nacos、RocketMQ、Seata分布式事务等技术的项目,核心业务是秒杀以及支付订单。 基于SpringCloud的秒杀项目,集合了zookeeper、redis、支付宝支付...