dpHibernate:serializerFactory 未由 Spring 初始化 ->服务访问时出现 NullPointerException
我正在尝试使用 BlazeDS 4.0.0.14931、Spring 3.0.5 和 Spring-BlazeDS-Integration 1.5.0.M2 在 Apache Tomcat 7.0.12 上运行 dpHibernate 2.0 RC6
使用以下配置,服务器可以正常启动,但一旦我想通过 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 访问)
startInternal INFO:启动 Servlet 引擎:Apache Tomcat/7.0.12 11.04.2011 18:34:19 org.apache.catalina.core.ApplicationContext 日志信息:初始化 Spring 根 WebApplicationContext 1027 [线程 2] 信息 org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final 1066 [Thread-2] INFO org.hibernate.cfg.Environment - 休眠 3.6.2.最终 1074 [线程 2] 信息 org.hibernate.cfg.Environment - 未找到 hibernate.properties 1085 [主题 2] 信息 org.hibernate.cfg.Environment - 字节码提供程序名称:javassist 1116 [线程 2] 信息 org.hibernate.cfg.Environment - 使用 JDK 1.4 java.sql.Timestamp 处理 2146 [线程 2] 信息 org.hibernate.cfg.Configuration - 未找到 Hibernate 验证器: 忽略 2182 [Thread-2] 信息 org.hibernate.cfg.search.HibernateSearchEventListenerRegister - 无法找到 org.hibernate.search.event.FullTextIndexEventListener 在类路径上。休眠搜索是 未启用。分段阅读_第 2194 章 org.hibernate.connection.ConnectionProviderFactory - 初始化连接提供者:org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider 分段阅读_第 2658 章 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] INFO org.hibernate.dialect.Dialect - 使用 方言: org.hibernate.dialect.MySQLInnoDBDialect 分段阅读_第 2981 章 org.hibernate.transaction.TransactionFactoryFactory - 事务策略:org.springframework.orm.hibernate3.SpringTransactionFactory 2991 [线程 2] 信息 org.hibernate.transaction.TransactionManagerLookupFactory - 未配置 TransactionManagerLookup(在 JTA 环境中,使用 读写或事务性 不推荐二级缓存) 2991 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 期间自动冲洗 beforeCompletion(): 禁用 2991 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 会话结束时自动关闭 事务:已禁用 2991 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - JDBC 批处理大小:20 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 版本化数据的 JDBC 批量更新:禁用 2998 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 可滚动结果集:已启用 2998 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - JDBC3 getGenerateKeys():启用 2998 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 连接释放方式:自动3003 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 最大外连接获取深度:2 3003 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 默认批量获取大小:1 3003 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 生成带注释的 SQL:禁用 3003 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 按主键对 SQL 更新进行排序: 已禁用 3003 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - 订购 SQL 插入以进行批处理: 已禁用 3003 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - 查询翻译器: org.hibernate.hql.ast.ASTQueryTranslatorFactory 3023 [线程 2] 信息 org.hibernate.hql.ast.ASTQueryTranslatorFactory - 使用 ASTQueryTranslatorFactory 3023 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 查询语言替换:{} 3023 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - JPA-QL 严格合规性:禁用 3023 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 二级缓存:启用3023 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 查询缓存:已禁用 3029 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - 缓存区域工厂:org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge 分段阅读_第 3074 章 org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - 缓存提供者:org.hibernate.cache.HashtableCacheProvider 分段阅读_第 3084 章 org.hibernate.cfg.SettingsFactory - 优化缓存以实现最少的放置: 已禁用 3084 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 结构化二级缓存条目: 已禁用 3131 [线程 2] 信息 org.hibernate.cfg.SettingsFactory - 将所有 SQL 回显到标准输出 3138 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 统计:已禁用 3138 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - 删除的实体合成标识符回滚:禁用 3138 [Thread-2] 信息 org.hibernate.cfg.SettingsFactory - 默认实体模式:pojo 3138 [Thread-2] INFO org.hibernate.cfg.SettingsFactory - 命名查询检查:启用 3138 [主题 2] 信息 org.hibernate.cfg.SettingsFactory - 检查核心中的可空性(应该是 当 Bean 验证打开时禁用): 启用 3239 [线程 2] 信息 org.hibernate.impl.SessionFactoryImpl - 构建会话工厂 3282 [Thread-2] INFO org.hibernate.type.BasicTypeRegistry - 类型注册 [blob] 覆盖 以前的 : org.hibernate.type.BlobType@17f7be7b 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [java.sql.Blob] 覆盖以前的: org.hibernate.type.BlobType@17f7be7b 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [materialized_clob] 覆盖以前的: org.hibernate.type.MaterializedClobType@9fa8988 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [wrapper_materialized_blob] 覆盖 以前的 : org.hibernate.type.WrappedMaterializedBlobType@1f5b44d6 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [clob] 覆盖 以前的 : org.hibernate.type.ClobType@21044daf 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [java.sql.Clob] 覆盖以前的: org.hibernate.type.ClobType@21044daf 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [characters_clob] 覆盖以前的: org.hibernate.type.PrimitiveCharacterArrayClobType@21882d18 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [wrapper_characters_clob] 覆盖 以前的 : org.hibernate.type.CharacterArrayClobType@734893da 分段阅读_第 3282 章 org.hibernate.type.BasicTypeRegistry - 类型注册 [materialized_blob] 覆盖以前的: org.hibernate.type.MaterializedBlobType@21e30857 分段阅读_第 3379 章 org.hibernate.impl.SessionFactoryObjectFactory - 未将工厂绑定到 JNDI,未配置 JNDI 名称 11.04.2011 18:34:36 org.apache.catalina.core.ApplicationContext 日志信息:初始化 Spring 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 启动信息:服务器在 21332 毫秒内启动 11.04.2011 18:49:02 org.apache.catalina.core.StandardWrapperValve 调用 SCHWERWIEGEND: servlet 的 Servlet.service() [RDSDispatchServlet] 上下文中 路径 [/myJavaServer] 抛出 例外 java.lang.NullPointerException at org.dphibernate.utils.HibernateUtil.getSessionFactory(未知 来源)于 org.dphibernate.filters.HibernateSessionServletFilter.getSessionFactory(未知 来源)位于 org.dphibernate.filters.AbstractHibernateSessionServletFilter.doFilter(未知 来源)于 org.apache.catalina.core.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) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 在 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) 在 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.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?
}
I am trying to get dpHibernate 2.0 RC6 running on an Apache Tomcat 7.0.12 with BlazeDS 4.0.0.14931, Spring 3.0.5 and Spring-BlazeDS-Integration 1.5.0.M2
With the following configuration the server starts fine, but as soon as I want to access a service or the RDSDispatchServlet via FlashBuilder4 DCD I am getting a NullPointerException. It seems the serializerFactory is not correctly injected into the dpHibernate HibernateUtil. Did I miss something in the configuration in 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 default configuration file)
<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 (definitions of services available for 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 (configuration of 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 (imported in 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 (on service access or rds access via FB4 DCD)
startInternal INFO: Starting Servlet
Engine: Apache Tomcat/7.0.12
11.04.2011 18:34:19 org.apache.catalina.core.ApplicationContext
log INFO: Initializing Spring root
WebApplicationContext 1027 [Thread-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 -
Bytecode provider name : javassist
1116 [Thread-2] INFO
org.hibernate.cfg.Environment - using
JDK 1.4 java.sql.Timestamp handling
2146 [Thread-2] INFO
org.hibernate.cfg.Configuration -
Hibernate Validator not found:
ignoring 2182 [Thread-2] INFO
org.hibernate.cfg.search.HibernateSearchEventListenerRegister
- Unable to find org.hibernate.search.event.FullTextIndexEventListener
on the classpath. Hibernate Search is
not enabled. 2194 [Thread-2] INFO
org.hibernate.connection.ConnectionProviderFactory
- Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2658 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Database ->
name : MySQL
version : 5.0.51a-24+lenny5-log
major : 5
minor : 0 2658 [Thread-2] INFO org.hibernate.cfg.SettingsFactory -
Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.15 (
Revision: ${bzr.revision-id} )
major : 5
minor : 1 2861 [Thread-2] INFO org.hibernate.dialect.Dialect - Using
dialect:
org.hibernate.dialect.MySQLInnoDBDialect
2981 [Thread-2] INFO
org.hibernate.transaction.TransactionFactoryFactory
- Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
2991 [Thread-2] INFO
org.hibernate.transaction.TransactionManagerLookupFactory
- No TransactionManagerLookup configured (in JTA environment, use of
read-write or transactional
second-level cache is not recommended)
2991 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Automatic flush during
beforeCompletion(): disabled 2991
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Automatic session close at end of
transaction: disabled 2991 [Thread-2]
INFO org.hibernate.cfg.SettingsFactory
- JDBC batch size: 20 2991 [Thread-2] INFO org.hibernate.cfg.SettingsFactory
- JDBC batch updates for versioned data: disabled 2998 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Scrollable result sets: enabled 2998
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
JDBC3 getGeneratedKeys(): enabled 2998
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Connection release mode: auto 3003
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Maximum outer join fetch depth: 2 3003
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Default batch fetch size: 1 3003
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Generate SQL with comments: disabled
3003 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Order SQL updates by primary key:
disabled 3003 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Order SQL inserts for batching:
disabled 3003 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Query translator:
org.hibernate.hql.ast.ASTQueryTranslatorFactory
3023 [Thread-2] INFO
org.hibernate.hql.ast.ASTQueryTranslatorFactory
- Using ASTQueryTranslatorFactory 3023 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Query language substitutions: {} 3023
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
JPA-QL strict compliance: disabled
3023 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Second-level cache: enabled 3023
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Query cache: disabled 3029 [Thread-2]
INFO org.hibernate.cfg.SettingsFactory
- Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
3074 [Thread-2] INFO
org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
- Cache provider: org.hibernate.cache.HashtableCacheProvider
3084 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Optimize cache for minimal puts:
disabled 3084 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Structured second-level cache entries:
disabled 3131 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Echoing all SQL to stdout 3138
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Statistics: disabled 3138 [Thread-2]
INFO org.hibernate.cfg.SettingsFactory
- Deleted entity synthetic identifier rollback: disabled 3138 [Thread-2]
INFO org.hibernate.cfg.SettingsFactory
- Default entity-mode: pojo 3138 [Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Named query checking : enabled 3138
[Thread-2] INFO
org.hibernate.cfg.SettingsFactory -
Check Nullability in Core (should be
disabled when Bean Validation is on):
enabled 3239 [Thread-2] INFO
org.hibernate.impl.SessionFactoryImpl
- building session factory 3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [blob] overrides
previous :
org.hibernate.type.BlobType@17f7be7b
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [java.sql.Blob]
overrides previous :
org.hibernate.type.BlobType@17f7be7b
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [materialized_clob]
overrides previous :
org.hibernate.type.MaterializedClobType@9fa8988
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration
[wrapper_materialized_blob] overrides
previous :
org.hibernate.type.WrappedMaterializedBlobType@1f5b44d6
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [clob] overrides
previous :
org.hibernate.type.ClobType@21044daf
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [java.sql.Clob]
overrides previous :
org.hibernate.type.ClobType@21044daf
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [characters_clob]
overrides previous :
org.hibernate.type.PrimitiveCharacterArrayClobType@21882d18
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration
[wrapper_characters_clob] overrides
previous :
org.hibernate.type.CharacterArrayClobType@734893da
3282 [Thread-2] INFO
org.hibernate.type.BasicTypeRegistry -
Type registration [materialized_blob]
overrides previous :
org.hibernate.type.MaterializedBlobType@21e30857
3379 [Thread-2] INFO
org.hibernate.impl.SessionFactoryObjectFactory
- Not binding factory to JNDI, no JNDI name configured
11.04.2011 18:34:36 org.apache.catalina.core.ApplicationContext
log INFO: Initializing Spring
FrameworkServlet 'springMessageBroker'
11.04.2011 18:34:36 org.apache.coyote.AbstractProtocolHandler
start INFO: Starting ProtocolHandler
["http-bio-8080"]
11.04.2011 18:34:36 org.apache.coyote.AbstractProtocolHandler
start INFO: Starting ProtocolHandler
["ajp-bio-8009"]
11.04.2011 18:34:36 org.apache.catalina.startup.Catalina
start INFO: Server startup in 21332 ms
11.04.2011 18:49:02 org.apache.catalina.core.StandardWrapperValve
invoke SCHWERWIEGEND:
Servlet.service() for servlet
[RDSDispatchServlet] in context with
path [/myJavaServer] threw
exception
java.lang.NullPointerException at
org.dphibernate.utils.HibernateUtil.getSessionFactory(Unknown
Source) at
org.dphibernate.filters.HibernateSessionServletFilter.getSessionFactory(Unknown
Source) at
org.dphibernate.filters.AbstractHibernateSessionServletFilter.doFilter(Unknown
Source) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at
org.apache.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)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at
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.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at
java.lang.Thread.run(Thread.java:662)
org.dphibernate.utils.HibernateUtil (snippet)
private static ISerializerFactory serializerFactory; // should be injected by Spring
public static SessionFactory getSessionFactory() throws HibernateException
{
return serializerFactory.getSessionFactory(); // but is null on this call?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不需要 remotingConfig.xml,它似乎是导致您出现问题的原因。
通常,在 Spring 配置中,您显示的
HibernateUtil
类不会被使用(SpringContextSerializerFactory
返回 SessionFactory 以确保您从您的应用程序中获得正确的会话工厂)。 Spring 会话)但是,看起来您的 remotingConfig.xml 文件正在覆盖默认设置,迫使它使用旧的
HibernateUtil
方法,这会抛出您的 NPE。The remotingConfig.xml isn't needed, and appears to be what's causing your problems.
Typically, in a Spring configuration, the
HibernateUtil
class you've shown there isn't used (theSpringContextSerializerFactory
returns the SessionFactory to ensure you're getting the correct one from your Spring session)However, it looks like your remotingConfig.xml file is overwriting the default settings, forcing it to use the old
HibernateUtil
approach, which is throwing your NPE.