0

我正在尝试让 dpHibernate 2.0 RC6 在带有 BlazeDS 4.0.0.14931、Spring 3.0.5 和 Spring-BlazeDS-Integration 1.5.0.M2 的 Apache Tomcat 7.0.12 上运行

使用以下配置,服务器可以正常启动,但只要我想通过 FlashBuilder4 DCD 访问服务或 RDSDispatchServlet,我就会收到 NullPointerException。似乎 serializerFactory 未正确注入 dpHibernate HibernateUtil。我是否错过了 remoting-config.xml 中的配置中的某些内容?

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
          version="2.5">

   <display-name>Server</display-name>
   <description>Server Side based on BlazeDS, Spring and Hibernate</description>
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <listener>
    <listener-class>flex.messaging.HttpFlexSession</listener-class>
   </listener>

   <!-- begin SPRING INTEGRATION -->
   <servlet>
     <servlet-name>springMessageBroker</servlet-name>
     <servlet-class>
       org.springframework.web.servlet.DispatcherServlet
     </servlet-class>
     <!-- <init-param> -->
     <!-- <param-name>contextConfigLocation</param-name> -->
     <!-- <param-value></param-value> Do not use if using ContextLoaderListener (would load app context twice -> Error) -->
     <!-- </init-param> -->
     <init-param>
        <param-name>services.configuration.file</param-name>
        <param-value>/WEB-INF/flex/services-config.xml</param-value>
     </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springMessageBroker</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
  </servlet-mapping>
  <!-- end SPRING INTEGRATION -->

  <!-- begin rds -->
  <servlet>
    <servlet-name>RDSDispatchServlet</servlet-name>
    <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
    <init-param>
        <param-name>useAppserverSecurity</param-name>
        <param-value>false</param-value>
    </init-param>        
    <init-param>
        <param-name>messageBrokerId</param-name>
        <param-value>_messageBroker</param-value>
    </init-param>        
    <load-on-startup>10</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>RDSDispatchServlet</servlet-name>
    <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
  </servlet-mapping>
  <!-- end rds -->

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>

  <filter>
    <filter-name>dpHibernateSessionFilter</filter-name>
    <filter-class>org.dphibernate.filters.HibernateSessionServletFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>dpHibernateSessionFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

applicationContext.xml(Spring Servlet 默认配置文件)

<beans  xmlns="http://www.springframework.org/schema/beans"
    xmlns:flex="http://www.springframework.org/schema/flex"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/flex
        http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <import resource="flexContext.xml" />
    <import resource="dataAccessContext.xml" />
    <import resource="dpHibernateContext.xml"/>

    <!-- Enable Spring Transaction Manager with Annotations -->
    <tx:annotation-driven />

    <context:annotation-config />

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations" value="/WEB-INF/server.properties" /></bean>

    <context:component-scan base-package="com.mycompany.myproject.*" />
</beans>

flexContext.xml(可用于 flex 的服务定义)

<beans  xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:flex="http://www.springframework.org/schema/flex"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/flex      
        http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">


    <flex:message-destination id="chat"/>

    <flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml">
            <flex:remoting-service default-adapter-id="dpHibernateRemotingAdapter" default-channels="my-amf,my-secure-amf" />
            <flex:message-service default-channels="my-streaming-amf,my-polling-amf"/>
    </flex:message-broker>
</beans>

fpHibernateContext.xml(dpHibernate的配置)

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:flex="http://www.springframework.org/schema/flex"  
      xmlns:security="http://www.springframework.org/schema/security"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/aop
                          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                          http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-3.0.xsd
                          http://www.springframework.org/schema/flex 
                          http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
                          http://www.springframework.org/schema/security 
                          http://www.springframework.org/schema/security/spring-security-3.0.xsd        
                          http://www.springframework.org/schema/tx 
                          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                          http://www.springframework.org/schema/util 
                          http://www.springframework.org/schema/util/spring-util-3.0.xsd
                          ">
  <!-- Defines the remoting adapter, which intercepts inbound & outbound messages, and routes them thruogh dpHibernate -->
  <bean id="dpHibernateRemotingAdapter"
    class="org.springframework.flex.core.ManageableComponentFactoryBean">
    <constructor-arg value="org.dphibernate.adapters.RemotingAdapter" />
    <property name="properties">        
      <value>
      {"dpHibernate" :
        {
          "serializerFactory" : "org.dphibernate.serialization.SpringContextSerializerFactory"
        }
      }
      </value>
    </property>
  </bean>
  <bean id="dpHibernateMessagingAdapter"
    class="org.springframework.flex.core.ManageableComponentFactoryBean"> 
    <constructor-arg value="org.dphibernate.adapters.MessagingAdapter" /> 
  </bean> 

  <bean id="dataAccessService" class="org.dphibernate.services.SpringLazyLoadService" autowire="constructor">
    <flex:remoting-destination />
  </bean>

  <!-- Required -->
  <bean id="hibernateSessionFilter" class="org.dphibernate.filters.SpringHibernateSessionServletFilter" />

  <!-- The cache is used to prevent serializing the same object many times during serialization.  Required -->
  <bean id="dpHibernateCache" 
    class="org.dphibernate.serialization.DPHibernateCache" scope="prototype" />

  <!-- The main serializer. Converts outbound POJO's to ASObjects with dpHibernate proxies for lazy loading.  Required -->
  <bean id="dpHibernateSerializer"
    class="org.dphibernate.serialization.HibernateSerializer" scope="prototype">
    <property name="pageSize" value="10"/>
  </bean>
  <bean id="dpHibernateDeserializer" class="org.dphibernate.serialization.HibernateDeserializer" scope="prototype" />
  <!--  Handles entity updates (CRUD).  Required if using entity persistence. -->
  <bean id="objectChangeUpdater" 
    class="org.dphibernate.persistence.state.AuthenticatedObjectChangeUpdater" 
    scope="prototype">
    <property name="preProcessors" ref="dpHibernatePreProcessors" />
    <property name="postProcessors" ref="dpHibernatePostProcessors" />
  </bean>   
</beans>

remoting-config.xml(在 services-config.xml 中导入)

<service id="remoting-service" 
         class="flex.messaging.services.RemotingService"
         messageTypes="flex.messaging.messages.RemotingMessage">

  <adapters>
    <adapter-definition id="hibernate-object" class="org.dphibernate.adapters.RemotingAdapter" default="true">
      <properties>
        <hibernate>
          <sessionFactory>
            <class>org.dphibernate.utils.HibernateUtil</class>
            <getCurrentSessionMethod>getCurrentSession</getCurrentSessionMethod>    
          </sessionFactory>
        </hibernate>
      </properties>
    </adapter-definition>
    <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter"/>
  </adapters>

  <default-channels>
    <channel ref="my-amf"/>
  </default-channels>
</service>

NullPointerException(通过 FB4 DCD 访问服务或 rds 访问)

HibernateSearchEventListenerRegister - 无法在类路径上找到 org.hibernate.search.event.FullTextIndexEventListener。未启用休眠搜索。2194 [Thread-2] INFO org.hibernate.connection.ConnectionProviderFactory - 初始化连接提供程序:org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider 2658 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 数据库 -> 名称:MySQL 版本:5.0.51a-24+lenny5-log 主要:5 次要:0 2658 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 驱动程序 -> 名称:MySQL-AB JDBC 驱动程序版本:mysql-connector-java-5.1 .15(修订:${bzr.revision-id})主要:5 次要:1 2861 [Thread-2] 信息 org.hibernate.dialect.Dialect - 使用方言:org.hibernate.dialect。 org.dphibernate.utils.HibernateUtil.getSessionFactoryjava.lang.NullPointerException(未知来源)在 org.dphibernate.filters.HibernateSessionServletFilter.getSessionFactory(未知来源)在 org.dphibernate.filters.AbstractHibernateSessionServletFilter.doFilter(未知来源)在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243 ) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) 在 org.apache.catalina.core.StandardContextValve 的 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)。在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 调用(StandardContextValve.java:164) .catalina.valves.ErrorReportValve。在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 调用(ErrorReportValve.java:100) .coyote.http11.Http11Processor.process(Http11Processor.java:250) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process (Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:662)catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java: 250) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat 的 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) .util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:908) 在 java.lang.Thread.run(Thread.java:662)catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java: 250) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat 的 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) .util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:908) 在 java.lang.Thread.run(Thread.java:662)catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol. java:188) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 在 java .util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:662 )catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol. java:188) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 在 java .util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:662 )org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run( JioEndpoint.java:302) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread .run(Thread.java:662)org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run( JioEndpoint.java:302) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread .run(Thread.java:662)886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:662)886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:662)

org.dphibernate.utils.HibernateUtil(片段)

private static ISerializerFactory serializerFactory; // should be injected by Spring

public static SessionFactory getSessionFactory() throws HibernateException
{
    return serializerFactory.getSessionFactory(); // but is null on this call?
}
4

1 回答 1

0

不需要 remotingConfig.xml,这似乎是导致您的问题的原因。

通常,在 Spring 配置中,HibernateUtil未使用您在其中显示的类(SpringContextSerializerFactory返回 SessionFactory 以确保您从 Spring 会话中获得正确的类)

但是,看起来您的 remotingConfig.xml 文件正在覆盖默认设置,迫使它使用旧HibernateUtil方法,即抛出您的 NPE。

于 2011-04-12T13:26:34.237 回答