Struts+Hibernate+Spring 配置
来源:互联网 发布:手机声音增大软件 编辑:程序博客网 时间:2024/03/29 03:33
java web 开发中常用的 框架 就是 ,struts 1 ,hibernate ,spring 整合,
在这里把它贴出来,经常忘记,加深一下印象。
首先配置 基本的 struts 1
web.xml 配置方式如下,先加上这个配置:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
下面是spring 与 hibernate,
这个与hibernate 配置 ,细分成了 三个spring文件,看起来更加清晰。
先在web.xml 加入这个配置:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring-basic-Context.xml,
/WEB-INF/config/spring-dao-Context.xml,
/WEB-INF/config/spring-services-Context.xml
</param-value>
</context-param>
下面分别是 三个spring 配置,,简单的book操作,做个例子。
<!-- spring-basic-Context.xml 配置--
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/db.properties</value>
</list>
</property>
</bean>
<bean id="c3P0dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${DB.DRIVER}" />
<property name="jdbcUrl" value="${DB.URL}" />
<property name="user" value="${DB.USERNAME}" />
<property name="password" value="${DB.PASSWORD}" />
<property name="initialPoolSize" value="10" />
<property name="maxPoolSize" value="30" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="c3P0dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.jdbc.batch_size">25</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/birds/book/bean/Book.hbm.xml</value>
</list>
</property>
</bean>
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="myTxManager" />
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED,-com.birds.book.common.BookException</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Services</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
</beans>
<!-- spring-dao-Context.xml 配置-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
<bean id="bookDao" class="com.birds.book.dao.impl.BookDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
<!-- spring-services-Context.xml 配置-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
<bean id="bookServices" class="com.birds.book.services.impl.BookServicesImpl">
<property name="bookDaoImpl" ref="bookDao" />
</bean>
</beans>
<!-- spring-action-Context.xml 配置-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
<bean name="/book" class="com.birds.view.action.BookAction" scope="prototype">
<property name="bookServicesImpl" ref="bookServices" />
</bean>
</beans>
<!-- struts-config.xml 配置-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans>
<form-bean name="bookForm" type="com.birds.view.form.BookForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/book"
name="bookForm"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request">
<forward name="success" path="/book.jsp" />
</action>
</action-mappings>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/config/spring-action-Context.xml" />
</plug-in>
</struts-config>
以上配置完,都是依赖注入。 这些框架的配置 都差不多。主要还是根据实际的业务来 加其他的组件进去。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/birdsaction/archive/2008/12/14/3511018.aspx
- 配置Struts+spring+hibernate
- Spring+Hibernate+Struts配置
- spring+hibernate+struts配置
- Struts+Hibernate+Spring 配置
- struts spring hibernate 配置
- struts+spring+hibernate配置实例
- Spring+Hibernate+Struts环境配置
- Struts+Spring+Hibernate配置全过程
- MyEclipse配置struts+hibernate+spring
- MyEclipse配置struts+hibernate+spring
- struts+spring+hibernate配置实例
- struts+hibernate+spring事务配置
- struts+hibernate+spring事务配置
- struts+hibernate+spring事务配置
- struts+hibernate+spring事务配置
- struts+hibernate+spring手动配置
- Struts+Spring+Hibernate事务Spring配置
- 图解MyEclipse配置struts+hibernate+spring+FreeMarker
- Struts 2请求处理流程
- Linux下MySql多实例免安装部署
- linux fork 详解
- 在oracle中创建unique唯一约束(单列和多列)
- MFC ListBox属性介绍[http://kingsundi.bokee.com/viewdiary.12742899.html]
- Struts+Hibernate+Spring 配置
- 我余
- Spring 联合Hibernate ,Struts开发之基本配置
- 房地产业务学习(06)-开发项目管理的难点分析&IT系统价值
- 试用了netty
- css中浮动错误
- 获取时间的几种方式
- c++各大名库
- 快速排序