Spring 4 + Struts 2 + Hibernate集成教程

以前,我已经介绍过spring 3 + hibernate集成示例和struts 2 hello world示例。在本教程中,我将讨论将spring框架与Struts和Hibernate结合使用时要牢记的所有重要点。另外,请注意,本教程使用了其他次要但很重要的概念,例如日志记录,TLD的使用和事​​务以及已集成到本教程中。因此,请记住还要检查其详细信息。

在本教程中,我将使用简单的功能(例如全部获取,添加和删除)来构建员工管理屏幕。它看起来像这样:

Spring支撑的主屏幕 Hibernate 集成

我将按照以下步骤讨论集成过程:

1)集成概述
2)Spring + Struts集成
3)Spring + Hibernate集成
4)其他集成功能
    a)Log4j 
    b)TLD 
    c)事务
5)要记住的要点
6)教程中使用的数据库架构
7)下载源代码

1)整合概述

在进入集成细节之前,让我们先确定为什么需要集成。像Struts一样,Spring也可以充当MVC实现。这两个框架都有其优点和缺点,但仍然有许多人会同意Spring会更好,并提供更多的功能。对我来说,只有两种情况,您需要本教程中提供的信息:

i)您有一个用Struts编写的旧应用程序,并且想要使用spring来提高应用程序的功能很多倍。
ii)您真的想根据自己的原因来学习它。

否则,我不知道为什么有人会在Spring选择支柱。如果您知道其他一些好的理由,请与我们所有人分享。那挺棒的。

继续,在本教程中,我将动作管理从Struts委派给Spring。进行委派的原因是,通过Spring上下文实例化Action类时,它可以使用spring在其自己的MVC实现中为其提供的Controller类的所有其他功能。因此,您将获得所有spring功能以及struts Action类,以具有包括其ActionForm概念在内的控制器逻辑。

2)Spring + Struts集成

这是核心逻辑,从注册ContextLoaderListenerStrutsPrepareAndExecuteFilter在web.xml中开始。ContextLoaderListener使用init参数contextConfigLocation并负责设置和启动Spring WebApplicationContext。现在,struts将在与Spring相关的服务中特别是在依赖注入DI中利用这一上下文。

StrutsPrepareAndExecuteFilter在类路径中查找struts.xml文件,并配置strut的特定内容,例如Action映射,全局转发和其他在struts.xml文件中定义的内容。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://www.oracle.com/technetwork/java/index.html; id="WebApp_ID" version="2.5">
    
  <display-name>Spring+Struts+Hibernate Integration Example</display-name>
    <welcome-file-list>
        <welcome-file>/WEB-INF/index.jsp</welcome-file>
    </welcome-file-list>
    
    <!-- Specify the spring context information location;
    Default location is applicationContext.xml file in classpath
     -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:beans.xml</param-value>
    </context-param>
    <!-- Bootstrap listener to start up and shut down Spring's root WebApplicationContext. -->
    <listener
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class
    </listener>
    <!-- Handles both the preparation and execution phases of the Struts dispatching process. -->
    <filter
        <filter-name>struts2</filter-name
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>0</param-value>
        </init-param>
    </filter
    <filter-mapping
        <filter-name>struts2</filter-name
        <url-pattern>/*</url-pattern
    </filter-mapping
    <!-- Struts Tag Library Descriptors -->
    <jsp-config>
        <taglib>
            <taglib-uri>/tags/struts-bean</taglib-uri>
            <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/tags/struts-html</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/tags/struts-logic</taglib-uri>
            <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/tags/struts-nested</taglib-uri>
            <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>

在第二步中,您将在struts.xml文件中创建操作映射,如下所示:

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
<struts>
    <!-- devMode is helpful when you want some extra logs for debugging -->
    <constant name="struts.devMode" value="false" />
    <!-- Global message resource;
         Otherwise you will have seperate message resource for each Action
    -->
    <constant name="struts.custom.i18n.resources" value="messages" />
    <!--
        This is important if you are planning to have slashes in Action URLs
        e.g. In this demo, employee is deleted using URL /delete/10
        This this is set to false; then struts will try to find mapping for
        URL "/10" instaed of "/delete/10"
     -->
    <constant name="struts.enable.SlashesInActionNames" value="true"/>
     
    <!-- Normal Action mappings are defined here -->
    <package name="default" namespace="" extends="struts-default">
        <!-- Two things to Notice:
             1) class is set to 'editEmployeeAction' which is bean defined by Spring context
             2) We have given the method to be called here as well;
        -->
        <action name="list" class="editEmployeeAction" method="listEmployees">
            <result>/view/editEmployeeList.jsp</result>
        </action>
        <action name="add" class="editEmployeeAction" method="addEmployee">
            <result type="redirect">/list</result>
        </action>
        <action name="delete/*" class="editEmployeeAction" method="deleteEmployee">
            <param name="employee.id">{1}</param>
            <result type="redirect">/list</result>
        </action>
        <action name="*" class="editEmployeeAction" method="listEmployees">
          <result>/view/editEmployeeList.jsp</result>
        </action>
    </package>
    
</struts>
在单独的strut应用程序中,我们将在“ class”属性中具有完整的Action Class及其包装信息。在这里,我们将类名命名为editEmployeeAction。它在哪里定义?我们将要求Spring为我们查找。

Spring上下文文件beans.xml是典型的Spring单独上下文文件,具有Web应用程序正常工作所需的所有内容,其中包括editEmployeeActionstruts正在寻找的bean定义。

beans.xml

<?xml  version="1.0" encoding="UTF-8"?>
    
    <!-- This bean has been referred fron struts.xml file; So type it correctly; -->
    <!-- Make scope prototype; This is really important. -->
    <bean name="editEmployeeAction" class="com.how2codex.controller.EditEmployeeAction" scope="prototype">
         <property name="employeeManager">
            <ref bean="employeeManager"/>
         </property>
    </bean>
    
    <!-- These beans are injected automatically by spring context -->
    <bean id="employeeDAO" class="com.how2codex.dao.EmployeeDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <bean id="employeeManager" class="com.how2codex.service.EmployeeManagerImpl">
        <property name="employeeDAO" ref="employeeDAO"/>
    </bean>
    
    <!-- Configure jdbc.properties -->
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />
 
    <!-- Data Source configuration -->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
        p:password="${jdbc.password}" />
 
    <!-- Configure hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
    <!-- Run SQL queries in transactions -->
    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
</beans>

这是将strut与spring框架集成在一起所需要做的一切。现在,您的动作类如下所示:

EditEmployeeAction.java

package com.how2codex.controller;
import java.util.List;
import org.apache.log4j.Logger;
import com.how2codex.entity.EmployeeEntity;
import com.how2codex.service.EmployeeManager;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
public class EditEmployeeAction extends ActionSupport implements Preparable
{
    private static final long serialVersionUID = 1L;
    
    //Logger configured using log4j
    private static final Logger logger = Logger.getLogger(EditEmployeeAction.class);
    
    //List of employees; Setter and Getter are below
    private List<EmployeeEntity> employees;
    
    //Employee object to be added; Setter and Getter are below
    private EmployeeEntity employee;
    
    //Employee manager injected by spring context; This is cool !!
    private EmployeeManager employeeManager;
    //This method return list of employees in database
    public String listEmployees() {
        logger.info("listEmployees method called");
        employees = employeeManager.getAllEmployees();
        return SUCCESS;
    }
    //This method will be called when a employee object is added
    public String addEmployee() {
        logger.info("addEmployee method called");
        employeeManager.addEmployee(employee);
        return SUCCESS;
    }
    //Deletes a employee by it's id passed in path parameter
    public String deleteEmployee() {
        logger.info("deleteEmployee method called");
        employeeManager.deleteEmployee(employee.getId());
        return SUCCESS;
    }
    
    //This method will be called before any of Action method is invoked;
    //So some pre-processing if required.
    @Override
    public void prepare() throws Exception {
        employee = null;
    }
    //Getters and Setters hidden
}

Spring还将DAO引用注入到Manager类。

EmployeeManagerImpl.java

package com.how2codex.service;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.how2codex.dao.EmployeeDAO;
import com.how2codex.entity.EmployeeEntity;
public class EmployeeManagerImpl implements EmployeeManager
{
    //Employee dao injected by Spring context
    private EmployeeDAO employeeDAO;
    
    //This method will be called when a employee object is added
    @Override
    @Transactional
    public void addEmployee(EmployeeEntity employee) {
        employeeDAO.addEmployee(employee);
    }
    
    //This method return list of employees in database
    @Override
    @Transactional
    public List<EmployeeEntity> getAllEmployees() {
        return employeeDAO.getAllEmployees();
    }
    //Deletes a employee by it's id
    @Override
    @Transactional
    public void deleteEmployee(Integer employeeId) {
        employeeDAO.deleteEmployee(employeeId);
    }
    
    //This setter will be used by Spring context to inject the dao's instance
    public void setEmployeeDAO(EmployeeDAO employeeDAO) {
        this.employeeDAO = employeeDAO;
    }
}

3)Spring + Hibernate集成

现在我们必须将 Hibernate 集成到应用程序中。最好的地方是利用Spring的强大功能进行集成,以充分利用依赖注入DI来与不同的ORM一起使用。

上面的bean.xml文件中已经给出了spring所需的 Hibernate 依赖关系。您将需要的其他文件是:

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
 
<hibernate-configuration>
    <session-factory>
        <mapping class="com.how2codex.entity.EmployeeEntity" />
    </session-factory>
</hibernate-configuration>

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/test
jdbc.username=root
jdbc.password=password

EmployeeDaoImpl.java

package com.how2codex.dao;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import com.how2codex.entity.EmployeeEntity;
@Repository
public class EmployeeDaoImpl implements EmployeeDAO 
{
    //Session factory injected by spring context
    private SessionFactory sessionFactory;
    
    //This method will be called when a employee object is added
    @Override
    public void addEmployee(EmployeeEntity employee) {
        this.sessionFactory.getCurrentSession().save(employee);
    }
    //This method return list of employees in database
    @SuppressWarnings("unchecked")
    @Override
    public List<EmployeeEntity> getAllEmployees() {
        return this.sessionFactory.getCurrentSession().createQuery("from EmployeeEntity").list();
    }
    //Deletes a employee by it's id
    @Override
    public void deleteEmployee(Integer employeeId) {
        EmployeeEntity employee = (EmployeeEntity) sessionFactory.getCurrentSession()
                                        .load(EmployeeEntity.class, employeeId);
        if (null != employee) {
            this.sessionFactory.getCurrentSession().delete(employee);
        }
    }
    //This setter will be used by Spring context to inject the sessionFactory instance
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}

供您参考,EmployeeEntity类如下所示:

EmployeeEntity.java

package com.how2codex.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="EMPLOYEE")
public class EmployeeEntity {
     
    @Id
    @Column(name="ID")
    @GeneratedValue
    private Integer id;
     
    @Column(name="FIRSTNAME")
    private String firstname;
 
    @Column(name="LASTNAME")
    private String lastname;
 
    @Column(name="EMAIL")
    private String email;
     
    @Column(name="TELEPHONE")
    private String telephone;
     
    //Setters and Getters
}

4)其他集成功能

除了struts + spring + hibernate,我们还使用以下组件来构建应用程序。

a)Log4j

Spring通过log4j在类路径中扫描自动配置日志记录。我们使用pom.xml文件添加了log4j依赖项。现在,您只需要在类路径中放置一个log4j.xml或log4j.properties文件。

log4j.properties

log4j.rootLogger=info, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:/log/demo.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

b)顶级域名

如果您查看web.xml文件,我们在其中包括了一些TLD。我们可以随时在视图层中使用它们,如下所示:

editEmployeeList.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Spring-4 + Struts-3 + Hibernate Integration Demo</title>
    <style>
    table.list
    {
        border-collapse:collapse;
        width: 40%;
    }
    table.list, table.list td, table.list th
    {
        border:1px solid gray;
        padding: 5px;
    }
    </style>
</head>
<body>
 
<h2>Spring-4 + Struts-3 + Hibernate Integration Demo</h2>
 
<s:form method="post" action="add">
    <table>
        <tr>
            <td><s:textfield key="label.firstname" name="employee.firstname"/></td>
        </tr>
        <tr>
            <td><s:textfield key="label.lastname" name="employee.lastname"/></td>
        </tr>
        <tr>
            <td><s:textfield key="label.email" name="employee.email"/></td>
        </tr>
        <tr>
            <td><s:textfield key="label.telephone" name="employee.telephone"/></td>
        </tr>
        <tr>
            <td>
                <s:submit key="label.add"></s:submit>
            </td>
        </tr>
    </table>
</s:form>
 
     
<h3>Employees</h3>
<c:if  test="${!empty employees}">
    <table class="list">
        <tr>
            <th align="left">Name</th>
            <th align="left">Email</th>
            <th align="left">Telephone</th>
            <th align="left">Actions</th>
        </tr>
        <c:forEach items="${employees}" var="emp">
            <tr>
                <td>${emp.lastname}, ${emp.firstname} </td>
                <td>${emp.email}</td>
                <td>${emp.telephone}</td>
                <td><a href="delete/${emp.id}">delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
 
</body>
</html>

c)交易

EmployeeManagerImpl.java在诸如getAllEmployees()和deleteEmployee()之类的方法中使用注解@Transactional。这实际上是在单个事务中运行在此方法下执行的所有数据库查询。您在beans.xml上下文文件中这样声明了事务依赖性。

<!-- Run SQL queries in transactions -->
<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

5)要记住的要点

a) 如果运行时无法找到lib文件夹中存在的类,则将来自项目依赖项的jar文件添加到项目部署程序集中。

b)在bean.xml中定义的Action类的范围设置为“ prototype”。Spring提供的bean的默认范围是单例,并且必须为每个请求创建新的Struts Action类,因为它包含特定于用户会话的数据。为了容纳两者,请将Action类bean标记为原型。

c)
在运行该应用程序之前,请不要忘记设置数据库。如果安装不正确,将导致您出现一些异常。

d)另外,还请包括 struts2-spring-plugin在项目运行时依赖项中。

6)教程中使用的数据库架构

下表已在MySQL中的名为“ test”的数据库中创建。

CREATE TABLE EMPLOYEE
(
    ID          INT PRIMARY KEY AUTO_INCREMENT,
    FIRSTNAME   VARCHAR(30),
    LASTNAME    VARCHAR(30),
    TELEPHONE   VARCHAR(15),
    EMAIL       VARCHAR(30),
    CREATED     TIMESTAMP DEFAULT NOW()
);

如果您打算自己构建应用程序,则下面在此应用程序中使用的直接给定结构将为您提供帮助。

Spring Struts Hibernate 集成的目录结构
Spring Struts Hibernate 集成的目录结构

pom.xml在以所有项目的依赖关系(一些额外的)这个项目中使用文件如下:

pom.xml

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.how2codex.app</groupId>
  <artifactId>Spring4Struts2HibernateIntegration</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Spring4Struts2HibernateIntegration Maven Webapp</name>
  <!-- JBoss repository for Hibernate -->
  <repositories>
    <repository>
        <id>JBoss repository</id>
    </repository>
  </repositories>
  <properties>
    <org.springframework.version>4.0.3.RELEASE</org.springframework.version>
  </properties>
  <dependencies>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.16.2</version>
    </dependency>
    
   <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-spring-plugin</artifactId>
        <version>2.3.16.2</version>
    </dependency>
    
     <!--
        Core utilities used by other modules.
        Define this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${org.springframework.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
        <scope>runtime</scope>
    </dependency>
            
    <!--
        Bean Factory and JavaBeans utilities (depends on spring-core)
        Define this if you use Spring Bean APIs (org.springframework.beans.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <!--
        Application Context (depends on spring-core, spring-expression, spring-aop, spring-beans)
        This is the central artifact for Spring's Dependency Injection Container and is generally always defined
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <!--
        Aspect Oriented Programming (AOP) Framework (depends on spring-core, spring-beans)
        Define this if you use Spring AOP APIs (org.springframework.aop.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.6.2</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.1</version>
    </dependency>
            
    <!--
        Transaction Management Abstraction (depends on spring-core, spring-beans, spring-aop, spring-context)
        Define this if you use Spring Transactions or DAO Exception Hierarchy
        (org.springframework.transaction.*/org.springframework.dao.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <!--
        JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx)
        Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
     
    <!--
        Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and iBatis.
        (depends on spring-core, spring-beans, spring-context, spring-tx)
        Define this if you need ORM (org.springframework.orm.*)
    -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    
    <dependency
       <groupId>log4j</groupId
       <artifactId>log4j</artifactId
       <version>1.2.15</version
       <exclusions
         <exclusion
           <groupId>javax.mail</groupId
           <artifactId>mail</artifactId
         </exclusion
         <exclusion
           <groupId>javax.jms</groupId
           <artifactId>jms</artifactId
         </exclusion
         <exclusion
           <groupId>com.sun.jdmk</groupId
           <artifactId>jmxtools</artifactId
         </exclusion
         <exclusion
           <groupId>com.sun.jmx</groupId
           <artifactId>jmxri</artifactId
         </exclusion
       </exclusions
       <scope>runtime</scope
     </dependency
     
     <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.3.Final</version>
    </dependency>
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
 
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>
        
   <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>
    
  </dependencies>
  <build>
    <finalName>Spring3Struts2HibernateIntegration</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

7)下载源代码

下载以上示例的源代码或获取.war文件。

这一切将在Spring 4 + Struts 2 + Hibernate集成教程中完成。让我知道您的想法和疑问。

saigon has written 1440 articles

Leave a Reply