MyEclipse6.0.1整合Spring2.0+Struts1.2+Hibernate3.2

简要说明一些容易出问题的地方.
加载框架支持的顺序是:
Spring,Hibernate,Struts.

先加载Spring支持.
 MyEclipse6.0.1整合Spring2.0+Struts1.2+Hibernate3.2_第1张图片
注意在这里一定要把Hibernate3.2 Core 包加入.当然如果您需要
用注解来管理VO的话,也需要加入Hibernate 3.2 Annotations包.
Hibernate 3.2 Advanced可选.

注意在下一步的时候,把applicationContext.xml放在/WEB-INF下,当然
这不是必须的,不过放在这配置方便些.

第二步,加入Hibernate支持:
 MyEclipse6.0.1整合Spring2.0+Struts1.2+Hibernate3.2_第2张图片
在加载hibernate支持时候注意Hibernate3.1的包在这里不选.(否则有冲突)
对于Spring Persistence 持久化的包可选.

最后加载Struts1.2支持,比较简单,就不帖图了.
只要注意了图中的两个问题,一般就不会出现莫名奇妙的
Servlet Action is not Assiable 的异常了.

给出部分配置文件源码:
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  />
    
< global-exceptions  />
    
< global-forwards  />
    
< action-mappings >
        
< action  path ="/login"  parameter ="method" >
            
< forward  name ="ok"  path ="/ok.jsp"   />
        
</ action >
    
</ action-mappings >
    
< message-resources  parameter ="com.web.struts.ApplicationResources"   />
    
<!--  控制器  -->
    
< controller
        
processorClass ="org.springframework.web.struts.DelegatingRequestProcessor"   />
    
<!--  struts,spring集成插件  -->
    
< plug-in
        
className ="org.springframework.web.struts.ContextLoaderPlugIn" >
        
< set-property  property ="contextConfigLocation"
            value
="/WEB-INF/applicationContext.xml"   />
    
</ plug-in >
</ struts-config >


Web.xml:

<? xml version="1.0" encoding="UTF-8" ?>
< web-app  xmlns ="http://java.sun.com/xml/ns/j2ee"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  version ="2.4"  xsi:schemaLocation ="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
  
<!--  spring配置  -->
  
< context-param >
      
< param-name > contextConfigLocation </ param-name >
      
< param-value > /WEB-INF/applicationContext.xml </ param-value >
  
</ context-param >
  
< servlet >
      
< servlet-name > context </ servlet-name >
      
< servlet-class > org.springframework.web.struts.ContextLoaderPlugIn </ servlet-class >
  
</ servlet >
  
<!--  struts配置  -->
  
< 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 >
    
< init-param >
      
< param-name > debug </ param-name >
      
< param-value > 3 </ param-value >
    
</ init-param >
    
< init-param >
      
< param-name > detail </ param-name >
      
< param-value > 3 </ param-value >
    
</ init-param >
    
< load-on-startup > 0 </ load-on-startup >
  
</ servlet >
  
< servlet-mapping >
    
< servlet-name > action </ servlet-name >
    
< url-pattern > *.do </ url-pattern >
  
</ servlet-mapping >
  
< welcome-file-list >
    
< welcome-file > index.jsp </ welcome-file >
  
</ welcome-file-list >
</ web-app >


当然对于web.xml中的spring配置不是必须的(可选).

applicationContext.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 ="dataSource"
        class
="org.springframework.jdbc.datasource.DriverManagerDataSource" >
        
< property  name ="driverClassName"
            value
="com.mysql.jdbc.Driver" >
        
</ property >
        
< property  name ="url"  value ="jdbc:mysql://localhost/test" ></ property >
        
< property  name ="username"  value ="root" ></ property >
        
< property  name ="password"  value ="root" ></ property >
    
</ bean >
    
< bean  id ="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
        
< property  name ="dataSource" >
            
< ref  bean ="dataSource"   />
        
</ property >
        
< property  name ="hibernateProperties" >
            
< props >
                
< prop  key ="hibernate.dialect" >
                    org.hibernate.dialect.MySQLDialect
                
</ prop >
            
</ props >
        
</ property >
    
</ bean >
    
< bean  name ="/login"  class ="com.web.struts.action.LoginAction" >
    
</ bean >
    
</ beans >


当然写了一个LoginAction进行了测试,一切表现良好.
对于LoginAction和前台页就不贴出源码了,比较简单.

 

转自:http://www.blogjava.net/supercrsky/articles/174800.html

你可能感兴趣的:(spring,Hibernate,bean,struts,servlet)