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>Struts 2 Fileupload</display-name> 
  <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 <session-config>
<session-timeout>300</session-timeout>
</session-config> 
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
 <filter>
<filter-name>struts-cleanup</filter-name> 
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> 
  </filter>
<filter>
  <filter-name>struts2</filter-name> 
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>  
<filter-mapping>
  <filter-name>struts-cleanup</filter-name> 
  <url-pattern>/*</url-pattern> 
  </filter-mapping>
<filter-mapping>
  <filter-name>struts2</filter-name> 
  <url-pattern>/*</url-pattern> 
  </filter-mapping>
  
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</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/tx
        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        ">
<context:component-scan base-package="com.xingao" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.0.249:1521:FIRST"/>
<property name="username" value="oauser"/>
<property name="password" value="xingaooa"/>

</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/xingao/entity/W_user.hbm.xml</value>
<value>com/xingao/entity/W_workschedule.hbm.xml</value>
<value>com/xingao/entity/T_role.hbm.xml</value>
<value>com/xingao/entity/T_connection.hbm.xml</value>
<value>com/xingao/entity/T_node_role.hbm.xml</value>
<value>com/xingao/entity/T_node.hbm.xml</value>
<value>com/xingao/entity/T_nodefile.hbm.xml</value>
<value>com/xingao/entity/T_role_user.hbm.xml</value>
<value>com/xingao/entity/T_select.hbm.xml</value>
<value>com/xingao/entity/T_template.hbm.xml</value>
<value>com/xingao/entity/T_templatefile.hbm.xml</value>
<value>com/xingao/entity/T_W_role_user.hbm.xml</value>
<value>com/xingao/entity/W_connection.hbm.xml</value>
<value>com/xingao/entity/W_node_role.hbm.xml</value>
<value>com/xingao/entity/W_node.hbm.xml</value>
<value>com/xingao/entity/W_nodefile.hbm.xml</value>
<value>com/xingao/entity/W_role_user.hbm.xml</value>
<value>com/xingao/entity/W_role.hbm.xml</value>
<value>com/xingao/entity/W_select.hbm.xml</value>
<value>com/xingao/entity/W_usertype.hbm.xml</value>
<value>com/xingao/entity/W_workflow.hbm.xml</value>
<value>com/xingao/entity/W_workflowdailyrecord.hbm.xml</value>
<value>com/xingao/entity/W_workflowfile.hbm.xml</value>

</list>

</property> <property name="hibernateProperties">
             <props>
                 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                 <prop key="hibernate.show_sql">true</prop>
                 <prop key="hibernate.format_sql">false</prop>
        
                 <prop key="hibernate.jdbc.batch_size">50</prop>
             </props>
         </property>
         

</bean>
<!-- 以下为事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用基于注释式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="UserDaoImpl" class="com.xingao.dao.impl.UserDaoImpl"></bean>
<bean id="MyFlowDaoImpl" class="com.xingao.dao.impl.MyFlowDaoImpl"></bean>
</beans>
当运行tomcat是报错如下:
2013-2-20 10:15:51 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter OpenSessionInViewFilter
java.lang.ClassCastException: org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4038)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4692)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:701)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)框架filter

解决方案 »

  1.   

    把<filter>和对应的<filter-mapping>紧连着。别分开。java.lang.ClassCastException: org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor cannot be cast to javax.servlet.Filter都匹配错了
      

  2.   

    OpenSessionInViewInterceptor cannot be cast to javax.servlet.Filter
    类型转化错误,你是不是在配置文件中将拦截器当成过滤器了
      

  3.   


    这是两个完全不同的概念啊,javax.servlet.Filter 过滤器
    拦截器interceptor,spring的主要功能了,
    还是让大神给你详细解释吧