2011-04-11 37 views
0

我想在Apache Tomcat 7.0.12上使用BlazeDS 4.0.0.14931,Spring 3.0.5和Spring-BlazeDS-Integration 1.5運行dpHibernate 2.0 RC6。 0.M2dpHibernate:serializerFactory沒有被Spring初始化 - > NullPointerException在服務訪問

通過以下配置,服務器可以正常啓動,但只要我想通過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(春季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(適用於柔性服務的定義)

<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)

startInternal INFO:啓動的Servlet 發動機:的Apache Tomcat/7.0.12 11.04.2011 18點34分19秒org.apache.catalina.core.ApplicationContext 日誌INFO:初始化彈簧根 的WebApplicationContext 1027 [線程2] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final 1066 [Thread-2] INFO org.hibernate.cfg.Environment - Hibernate 3.6.2.Final 1074 [Thread-2] INFO org.hibernate.cfg.Environment - hibernate.properties not found 1085 [Thread-2] INFO org.hibernate.cfg.Environment - 字節碼提供程序名稱:javassist 1116 [線程2] INFO org.hibernate.cfg.Environment中 - 使用 JDK 1.4的java.sql.Timestamp處理 2146 [線程2] INFO org.hibernate.cfg.Configuration - Hibernate驗證未找到: 忽略2182 [Thread-2]信息 org.hibernate.cfg.search.HibernateSearchEventListenerRegister - 無法在類路徑中找到org.hibernate.search.event.FullTextIndexEventListener 。休眠搜索是 未啓用。 2194 [Thread-2]信息 org.hibernate.connection.ConnectionProviderFactory - 初始化連接提供程序:org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider 2658 [Thread-2] INFO org.hibernate.cfg。SettingsFactory - 數據庫 - > 名稱:MySQL的 版本:5.0.51a-24 + lenny5日誌 大:5 輕微:0 2658 [線程2] INFO org.hibernate.cfg.SettingsFactory - 驅動程序 - > 名稱:MySQL-AB JDBC驅動程序 版本:mysql-connector-java-5.1.15( 修訂版:$ {bzr.revision-id}) major:5 minor:1 2861 [線程2] INFO org.hibernate .dialect.Dialect - 使用 方言: org.hibernate.dialect.MySQLInnoDBDialect 2981 [線程2] INFO org.hibernate.transaction.TransactionFactoryFactory - Transacti上的策略:org.springframework.orm.hibernate3.SpringTransactionFactory 2991 [線程2] INFO org.hibernate.transaction.TransactionManagerLookupFactory - 無的TransactionManagerLookup配置(在JTA環境中,使用 讀寫或事務 第二級的高速緩存不推薦) 2991 [線程2] INFO org.hibernate.cfg.SettingsFactory - 自動沖洗時 beforeCompletion中():禁用2991 [線程2] INFO org.hibernate.cfg.SettingsFactory - 自動會話關閉 結束處理:已禁用2991 [Thread-2] INFO org.hibernate.cfg.Set tingsFactory - JDBC batch size:20 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 版本化數據的JDBC批量更新:已禁用2998 [Thread-2]信息 org.hibernate.cfg.SettingsFactory - Scrollable結果集:啓用2998 [線程2] INFO org.hibernate.cfg.SettingsFactory - JDBC3的getGeneratedKeys():啓用2998 [線程2] INFO org.hibernate.cfg.SettingsFactory - 連接釋放模式: auto 3003 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth:2 3003 [Thread-2] INFO o rg.hibernate.cfg.SettingsFactory - 默認批量抓取大小:3003 [線程2] INFO org.hibernate.cfg.SettingsFactory - 生成帶有註釋的SQL:禁用 3003 [線程2] INFO 組織。 hibernate.cfg.SettingsFactory - 訂單SQL更新由主鍵: 禁用3003 [線程2] INFO org.hibernate.cfg.SettingsFactory - 訂單SQL插入用於配料: 禁用3003 [線程2] INFO 有機.hibernate.cfg.SettingsFactory - 查詢翻譯器: org.hibernate.hql.ast.ASTQueryTranslatorFactory 3023 [線程-2]信息 org.hibernate.hql.ast.ASTQueryTranslatorFactory - 使用ASTQueryTranslatorFactory 3023 [線程2] INFO org.hibernate.cfg.SettingsFactory - 查詢語言取代:{} 3023 [線程2] INFO org.hibernate作爲。 cfg.SettingsFactory - JPA-QL嚴格遵守:禁用 3023 [線程2] INFO org.hibernate.cfg.SettingsFactory - 二級緩存:啓動3023 [線程2] INFO org.hibernate.cfg .SettingsFactory - 查詢緩存:已禁用3029 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 緩存區域工廠:org.hibernate.cache.impl.bridge。RegionFactoryCacheProviderBridge 3074 [線程2] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - 緩存提供商:org.hibernate.cache.HashtableCacheProvider 3084 [線程2] INFO org.hibernate.cfg.SettingsFactory - 爲最小的看跌期權 優化緩存: 禁用3084 [線程2] INFO org.hibernate.cfg.SettingsFactory - 結構化的第二級高速緩存器條目: 禁用3131 [線程2] INFO org.hibernate.cfg.SettingsFactory - 回覆所有SQL到標準輸出3138 [線程2]信息 org.hibernate.cfg.SettingsFactory - 個統計:禁用3138 [線程2] INFO org.hibernate.cfg.SettingsFactory - 刪除的實體合成標識符回滾:禁用3138 [線程2] INFO org.hibernate.cfg.SettingsFactory - 默認實體模式: POJO 3138 [線程2] INFO org.hibernate.cfg.SettingsFactory - 命名查詢檢查:啓用3138 [線程2] INFO org.hibernate.cfg.SettingsFactory - 核芯檢查可空(應該是 禁用當Bean驗證打開時): enabled 3239 [Thread-2] INFO org.hibernate.impl.SessionFactoryImpl - building session factory 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[BLOB]覆蓋 先前: [email protected] 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[的java.sql.Blob] 覆寫以前: [email protected] 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[materialized_clob] 覆寫以前: 有機[email protected] 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊 [wrapper_materialized_blob]覆蓋 先前: [email protected] 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[CLOB]將覆蓋先前 : 有機.hibernate.type.ClobType @ 21044daf 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[java.sql.Clob中] 覆寫以前: [email protected] 3282 [Thread-2]信息 org.hibernate.type.BasicTypeRegistry - 類型註冊[characters_clob] 覆寫以前: [email protected] 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊 [wrapper_characters_clob]覆蓋 先前: 有機.hibernate.type.CharacterArrayClobType @ 734893da 3282 [線程2] INFO org.hibernate.type.BasicTypeRegistry - 類型註冊[materialized_blob] 覆寫以前: [email protected] 3379 [Thread- 2] INFO org.hibernate.impl。SessionFactoryObjectFactory - 沒有約束力工廠JNDI,沒有JNDI名稱配置 11.04.2011十八時34分36秒org.apache.catalina.core.ApplicationContext 日誌信息:初始化春 FrameworkServlet的 'springMessageBroker' 11.04.2011 18:34: 36 org.apache.coyote.AbstractProtocolHandler 啓動信息:啓動ProtocolHandler [ 「HTTP-BIO-8080」] 11.04.2011 18點34分36秒org.apache.coyote.AbstractProtocolHandler 啓動信息:啓動ProtocolHandler [「AJP -bio-8009「] 11.04.2011 18:34:36 org.apache.catalina.startup.Catalina start INFO:服務器在21332啓動ms 11.04.2011 18:49:02 org.apache.catalina .core.StandardWrapperValve 調用SCHWERWIEGEND: Servlet.service()進行的servlet [RDSDispatchServlet]與 路徑上下文[/ myJavaServer]投擲 例外 顯示java.lang.NullPointerExceptionorg.dphibernate.utils.HibernateUtil .getSessionFactory(未知 源)處 org.dphibernate.filters.AbstractHibernateSessionServletFilter.doFilter(未知 源) org.dphibernate.filters.HibernateSessionServletFilter.getSessionFactory(未知 源)在 org.apache.catalina.c ore.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve。的java:240) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 在 有機.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 在 org.apache.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) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoo lExecutor $ Worker.runTask(ThreadPoolExecutor.java: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? 
} 
+0

凹凸,任何? – Rob 2011-04-12 08:31:24

回答

0

是不需要的remotingConfig.xml,並且似乎是什麼導致你的問題。

通常,在Spring配置,還有你的HibernateUtil班上有沒有使用(該SpringContextSerializerFactory返回的SessionFactory,以確保您得到您的春季會議正確的)

然而,看起來像你的remotingConfig.xml文件覆蓋默認設置,迫使它使用舊的HibernateUtil方法,這是扔你的NPE。

+0

作品!萬分感謝!不幸的是,解決這個問題導致了我另一個問題。由於這可能與我無關,所以我打開了另一個線程,如果你能幫助我,也會很高興,因爲我在網上找不到太多東西。 http://stackoverflow.com/questions/5648428/spring-blazeds-integration-illegalargumentexception-servletcontext-must-not-be – Rob 2011-04-13 11:30:30