web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- default: /WEB-INF/applicationContext.xml -->
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!--
<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
-->
<param-value>classpath:beans.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
bean.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com.per.liubo"/>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<!--
<property name="annotatedClasses"> <list>
<value>com.bjsxt.model.User</value>
<value>com.bjsxt.model.Log</value> </list> </property>
-->
<property name="packagesToScan">
<list>
<value>com.per.liubo.Model</value>
</list>
</property>
<!--
<property name="mappingResources"> <list>
<value>product.hbm.xml</value> </list> </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="hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="myTxManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<aop:config>
<aop:pointcut id="businessService"
expression="execution(public * com.per.liubo.service..*.add(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="businessService" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<!--<tx:method name="someOtherBusinessMethod" propagation="REQUIRES_NEW" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />-->
</tx:attributes>
</tx:advice>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
</beans>
jdbc.property
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/hibernate
jdbc.username=root
jdbc.password=wanmei
struts2.1.6 + spring 2.5.6 + hibernate 3.3.2
| antlr-2.7.6.jar | hibernate/lib/required | 解析HQL |
| aspectjrt | spring/lib/aspectj | AOP |
| aspectjweaver | .. | AOP |
| cglib-nodep-2.1_3.jar | spring/lib/cglib | 代理,二进制增强 |
| common-annotations.jar | spring/lib/j2ee | @Resource |
| commons-collections-3.1.jar | hibernate/lib/required | 集合框架 |
| commons-fileupload-1.2.1.jar | struts/lib | struts |
| commons-io-1.3.2 | struts/lib | struts |
| commons-logging-1.1.1 | 单独下载,删除1.0.4(struts/lib) | struts spring |
| dom4j-1.6.1.jar | hibernate/required | 解析xml |
| ejb3-persistence | hibernate-annotation/lib | @Entity |
| freemarker-2.3.13 | struts/lib | struts |
| hibernate3.jar | hibernate |
|
| hibernate-annotations | hibernate-annotation/ |
|
| hibernate-common-annotations | hibernate-annotation/lib |
|
| javassist-3.9.0.GA.jar | hiberante/lib/required | hibernate |
| jta-1.1.jar | .. | hibernate transaction |
| junit4.5 |
|
|
| mysql- |
|
|
| ognl-2.6.11.jar | struts/lib |
|
| slf4j-api-1.5.8.jar | hibernate/lib/required | hibernate-log |
| slf4j-nop-1.5.8.jar | hibernate/lib/required |
|
| spring.jar | spring/dist |
|
| struts2-core-2.1.6.jar | struts/lib |
|
| xwork-2.1.2.jar | struts/lib | struts2 |
| commons-dbcp | spring/lib/jarkata-commons |
|
| commons-pool.jar | .. |
|
| struts2-spring-plugin-2.1.6.jar | struts/lib |
|
本文介绍了一个基于Struts2、Spring和Hibernate框架的整合应用案例,包括配置文件web.xml和beans.xml的内容,以及数据库连接配置。通过具体代码展示了如何实现依赖注入、事务管理和持久层操作。
1978

被折叠的 条评论
为什么被折叠?



