希望高手能帮我指点一下,参考了很多网上资料,还是找不出问题。谢谢了。
PS:struts2.2.1+spring2.5+hebernate3.2  有struts2-spring-plugin-2.2.1.jar  
为了解决包冲突,我删除了包asm.jar,asm_attrs.jar,cglib-2.1.3.jar,struts2-codebehind-plugin-2.2.1.jar,
struts2-osgi-admin-bundle-2.2.1.jar,struts2-osgi-plugin-2.2.1.jar   我的具体配置在后面有贴。
另外,如果struts2的action不由spring管理的话,我试过了,action可以正常执行。但是一变成spring管理action就出错。
而且错误很奇怪,java.lang.NoSuchMethodException: issueinfo.action.thdoneActionImpl.index(),
但是我这个action根本没有index()也不需要。我觉得很大可能是struts2和spring结合时候环境问题。但是找不出来。我在浏览器地址栏输入http://localhost:8080/ssh_travelnew/list直接调用这个list action。错误如下:
HTTP Status 500 - --------------------------------------------------------------------------------
type Exception report
message 
description The server encountered an internal error () that prevented it from fulfilling this request.
exception 
java.lang.NoSuchMethodException: issueinfo.action.thdoneActionImpl.index()
java.lang.Class.getMethod(Class.java:1605)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.DefaultActionProxy.execute(DefaultActionProxy.java:141)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.18
配置如下:
struts.xml如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
 <constant name="struts.devMode" value="false" />
<package name="products" extends="struts-default">
<action name="list" class="thdoneActionImpl" method="list">

            <result>/travelhelpdone1.jsp</result>
        </action>
</package>
</struts>
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">
  
    <display-name>Travel</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<!-- ContextConfigLocation -->
<context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/applicationContext.xml</param-value>
   </context-param> <filter>
        <filter-name>struts2</filter-name>
        <!--<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> -->
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
                <init-param>
         <param-name>config</param-name>
         <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
        </init-param>
    </filter>

<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

<!-- Listener contextConfigLocation -->
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

解决方案 »

  1.   

    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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tool="http://www.springframework.org/schema/tool"
    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">
    <bean id="ssh_travel_DataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.mysql.jdbc.Driver">
    </property>
    <property name="url"
    value="jdbc:mysql://localhost:3306/travelparty">
    </property>
    <property name="username" value="root"></property>
    <property name="password" value="123456"></property>
    </bean>
    <bean id="exampleHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
      <property name="properties">
        <props>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.c3p0.minPoolSize">5</prop>
    <prop key="hibernate.c3p0.maxPoolSize">20</prop>
    <prop key="hibernate.c3p0.timeout">600</prop>
    <prop key="hibernate.c3p0.max_statement">50</prop>
    <prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
        </props>
      </property>
    </bean>
    <bean id="ssh_travelSessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="ssh_travel_DataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>issueinfo/Travelhdone.hbm.xml</value></list>
    </property>
    </bean>
    <bean id="thdoneActionImpl" class="issueinfo.action.thdoneActionImpl"
    scope="prototype">
    <property name="thdoneService">
    <ref bean="thdoneService" />
    </property>
    <property name="pagerService">
    <ref bean="pagerService" />
    </property>
    <property name="travelhdone">
    <ref bean="travelhdone" />
    </property>
    <property name="pager">
    <ref bean="pager" />
    </property>
    </bean>
    <!-- Services -->
    <bean id="thdoneService" class="issueinfo.services.thdoneServiceImpl">
    <property name="thdoneDao">
    <ref bean="TravelhdoneDao" />
    </property>
    </bean>
    <!-- DAO -->
    <bean id="TravelhdoneDao" class="issueinfo.TravelhdoneDAO">
    <property name="sessionFactory">
    <ref bean="ssh_travelSessionFactory" />
    </property>
    </bean>
    <bean id="travelhdone" class="issueinfo.Travelhdone">
    </bean>
    <bean id="pagerService" class="commons.PagerService">
    </bean>
    <bean id="pager" class="commons.Pager">
    </bean>
    </beans>thdoneAction.java如下:
    package issueinfo.action;
    public interface thdoneAction{

    public String list() throws Exception ;
    public String save() throws Exception ;
    public String load() throws Exception ;
    public String delete() throws Exception ;}
    thdoneActionImpl.java如下:
    package issueinfo.action;import java.sql.Timestamp;
    import java.util.Collection;import org.springframework.beans.factory.BeanFactory;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;import issueinfo.Travelhdone;
    import issueinfo.services.thdoneServiceImpl;
    import commons.AbstractAction;
    import commons.Pager;
    import commons.PagerService;
    import commons.logincheck;
    import com.opensymphony.xwork2.Action;public class thdoneActionImpl extends AbstractAction implements thdoneAction{

    private thdoneServiceImpl thdoneService;
    private PagerService pagerService; private Travelhdone travelhdone;
    private Pager pager; protected Collection availableItems;
    protected String currentPage;
    protected String pagerMethod;
    protected String totalRows;
    private String issueNo;
    protected String queryName;
    protected String queryValue;
    protected String searchName;
    protected String searchValue;
    protected String queryMap; public String list() throws Exception {
    if (queryMap == null || queryMap.equals("")) { } else {
    String[] str = queryMap.split("~");
    this.setQueryName(str[0]);
    this.setQueryValue(str[1]);
    } int totalRow = thdoneService.getRows2(this.getQueryName(), this
    .getQueryValue());
    pager = pagerService.getPager(this.getCurrentPage(), this
    .getPagerMethod(), totalRow);
    this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
    this.setTotalRows(String.valueOf(totalRow));
    availableItems = thdoneService.getthdones2(this.getQueryName(), this
    .getQueryValue(), pager.getPageSize(), pager.getStartRow());
    this.setQueryName(this.getQueryName());
    this.setQueryValue(this.getQueryValue()); this.setSearchName(this.getQueryName());
    this.setSearchValue(this.getQueryValue()); return SUCCESS;
    } public String load() throws Exception {
    if (issueNo!=null)
    travelhdone = thdoneService.getthdone(this.issueNo);

    return SUCCESS;
    } public String save() throws Exception {
    java.sql.Timestamp issue_date = new Timestamp(new java.util.Date().getTime());
    travelhdone.setUpdateDate(issue_date);
        
    if (travelhdone.getIssueNo()==null){
    travelhdone.setIssueDate(issue_date);
         travelhdone.setPhotoPath1("");
         travelhdone.setPhotoPath2("");
         travelhdone.setPhotoPath3("");
         travelhdone.setPhotoPath4("");
         travelhdone.setPhotoPath5("");
         travelhdone.setPhotoPath6("");
         travelhdone.setPhotoPath7("");
         travelhdone.setRegistDate(issue_date);
    thdoneService.addthdone(this.getTravelhdone());
    }else{
    thdoneService.updatethdone(this.getTravelhdone());
    } this.setQueryName(this.getQueryName());
    this.setQueryValue(this.getQueryValue()); if (this.getQueryName() == null || this.getQueryValue() == null
    || this.getQueryName().equals("")
    || this.getQueryValue().equals("")) { } else {
    queryMap = this.getQueryName() + "~" + this.getQueryValue();
    } return SUCCESS;
    } public String delete() throws Exception {
    thdoneService.deletethdone(this.getIssueNo()); if (this.getQueryName() == null || this.getQueryValue() == null
    || this.getQueryName().equals("")
    || this.getQueryValue().equals("")) { } else {
    queryMap = this.getQueryName() + "~" + this.getQueryValue();
    }
    return SUCCESS;
    } public Travelhdone getTravelhdone() {
    return travelhdone;
    } public void setTravelhdone(Travelhdone travelhdone) {
    this.travelhdone = travelhdone;
    } public thdoneServiceImpl getThdoneService() {
    return thdoneService;
    } public void setThdoneService(thdoneServiceImpl thdoneService) {
    this.thdoneService = thdoneService;
    } public Collection getAvailableItems() {
    return availableItems;
    }

    public void setAvailableItems(Collection availableItems) {
    this.availableItems=availableItems;
    }
    public String getCurrentPage() {
    return currentPage;
    } public void setCurrentPage(String currentPage) {
    this.currentPage = currentPage;
    } public String getPagerMethod() {
    return pagerMethod;
    } public void setPagerMethod(String pagerMethod) {
    this.pagerMethod = pagerMethod;
    } public Pager getPager() {
    return pager;
    } public void setPager(Pager pager) {
    this.pager = pager;
    } public String getTotalRows() {
    return totalRows;
    } public void setTotalRows(String totalRows) {
    this.totalRows = totalRows;
    } public String getIssueNo() {
    return issueNo;
    } public void setIssueNo(String issueNo) {
    this.issueNo = issueNo;
    } public String getQueryName() {
    return queryName;
    } public void setQueryName(String queryName) {
    this.queryName = queryName;
    } public String getQueryValue() {
    return queryValue;
    } public void setQueryValue(String queryValue) {
    this.queryValue = queryValue;
    } public String getSearchName() {
    return searchName;
    } public void setSearchName(String searchName) {
    this.searchName = searchName;
    } public String getSearchValue() {
    return searchValue;
    } public void setSearchValue(String searchValue) {
    this.searchValue = searchValue;
    } public String getQueryMap() {
    return queryMap;
    } public void setQueryMap(String queryMap) {
    this.queryMap = queryMap;
    } public PagerService getPagerService() {
    return pagerService;
    } public void setPagerService(PagerService pagerService) {
    this.pagerService = pagerService;
    }}
      

  2.   

    tomcat启动log如下:
    2010-12-7 18:33:46 org.apache.catalina.core.AprLifecycleListener init
    信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_02\bin;G:\develop envirement\Tomcat 6.0\bin
    2010-12-7 18:33:47 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2010-12-7 18:33:47 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 2003 ms
    2010-12-7 18:33:47 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2010-12-7 18:33:47 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.18
    2010-12-7 18:33:49 org.apache.catalina.core.ApplicationContext log
    信息: ContextListener: contextInitialized()
    2010-12-7 18:33:49 org.apache.catalina.core.ApplicationContext log
    信息: SessionListener: contextInitialized()
    2010-12-7 18:34:06 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Spring root WebApplicationContext
    INFO - Root WebApplicationContext: initialization started
    INFO - Refreshing [email=org.springframework.web.context.support.XmlWebApplicationContext@4e194f]org.springframework.web.context.support.XmlWebApplicationContext@4e194f[/email]: display name [Root WebApplicationContext]; startup date [Tue Dec 07 18:34:07 CST 2010]; root of context hierarchy
    INFO - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    INFO - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@4e194f]: [email=org.springframework.beans.factory.support.DefaultListableBeanFactory@b6f7f5]org.springframework.beans.factory.support.DefaultListableBeanFactory@b6f7f5[/email]
    INFO - Pre-instantiating singletons in [email=org.springframework.beans.factory.support.DefaultListableBeanFactory@b6f7f5]org.springframework.beans.factory.support.DefaultListableBeanFactory@b6f7f5[/email]: defining beans [ssh_travel_DataSource,exampleHibernateProperties,ssh_travelSessionFactory,thdoneActionImpl,thdoneService,TravelhdoneDao,travelhdone,pagerService,pager]; root of factory hierarchy
    INFO - Hibernate 3.2.5
    INFO - hibernate.properties not found
    INFO - Bytecode provider name : cglib
    INFO - using JDK 1.4 java.sql.Timestamp handling
    INFO - Mapping class: issueinfo.Travelhdone -> travelhdone
    INFO - Building new Hibernate SessionFactory
    INFO - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
    INFO - RDBMS: MySQL, version: 5.1.47-community
    INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.8 ( Revision: ${svn.Revision} )
    INFO - Using dialect: org.hibernate.dialect.MySQLDialect
    INFO - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
    INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    INFO - Automatic flush during beforeCompletion(): disabled
    INFO - Automatic session close at end of transaction: disabled
    INFO - JDBC batch size: 15
    INFO - JDBC batch updates for versioned data: disabled
    INFO - Scrollable result sets: enabled
    INFO - JDBC3 getGeneratedKeys(): enabled
    INFO - Connection release mode: auto
    INFO - Maximum outer join fetch depth: 2
    INFO - Default batch fetch size: 1
    INFO - Generate SQL with comments: disabled
    INFO - Order SQL updates by primary key: disabled
    INFO - Order SQL inserts for batching: disabled
    INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    INFO - Using ASTQueryTranslatorFactory
    INFO - Query language substitutions: {}
    INFO - JPA-QL strict compliance: disabled
    INFO - Second-level cache: enabled
    INFO - Query cache: disabled
    INFO - Cache provider: org.hibernate.cache.NoCacheProvider
    INFO - Optimize cache for minimal puts: disabled
    INFO - Structured second-level cache entries: disabled
    INFO - Statistics: disabled
    INFO - Deleted entity synthetic identifier rollback: disabled
    INFO - Default entity-mode: pojo
    INFO - Named query checking : enabled
    INFO - building session factory
    INFO - Not binding factory to JNDI, no JNDI name configured
    INFO - Running hbm2ddl schema update
    INFO - fetching database metadata
    INFO - updating schema
    INFO - table found: travelparty.travelhdone
    INFO - columns: [detail, photo_path1, r_user_id, issue_no, issue_date, city, destination, regist_date, title, end_date, p_user_id, province, update_date, photo_path6, photo_path7, photo_path4, photo_path5, start_date, photo_path2, photo_path3]
    INFO - foreign keys: []
    INFO - indexes: [primary, travelhdone_index1, travelhdone_index2]
    INFO - schema update complete
    INFO - Root WebApplicationContext: initialization completed in 18721 ms
    INFO - Parsing configuration file [struts-default.xml]
    INFO - Parsing configuration file [struts-plugin.xml]
    INFO - Parsing configuration file [struts.xml]
    INFO - Initializing Struts-Spring integration...
    INFO - Setting autowire strategy to name
    INFO - ... initialized Struts-Spring integration successfully
    ERROR - Unable to find parent packages osgi-default
    2010-12-7 18:34:48 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2010-12-7 18:34:49 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2010-12-7 18:34:49 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/129  config=null
    2010-12-7 18:34:49 org.apache.catalina.startup.Catalina start
    信息: Server startup in 62212 ms