jbpm4.4 跟Hibernate4不兼容问题

t_tianxingjian 2013-06-23

将jbpm4.4和SSH进行集成,用Junit进行测试的时候报错:

java.lang.IllegalStateException: Failed to load ApplicationContext
	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
	......
Caused by: java.lang.NullPointerException
	at org.jbpm.pvm.internal.processengine.SpringProcessEngine.create(SpringProcessEngine.java:65)
	at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:90)
	at org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine(SpringHelper.java:50)
	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)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)

 根据报错信息查看jbpm源码,发现是SpringProcessEngine类报空指针异常

LocalSessionFactoryBean localSessionFactoryBean = springProcessEngine.get(LocalSessionFactoryBean.class);

      Configuration hibernateConfiguration = localSessionFactoryBean.getConfiguration();

也就是localSessionFactoryBean为空,再查看springProcessEngine获取LocalSessionFactoryBean对象的方法是通过类型到Spring上下文去取得的:String[] names = applicationContext.getBeanNamesForType(type);。

到这里基本上就猜测是配置文件里面缺少这个类型配置,但是发现我也配置sessionFactory也是使用的

<bean id="sessionFactory"

class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

经过对比,SpringProcessEngine类里面LocalSessionFactoryBean引用是import org.springframework.orm.hibernate3.LocalSessionFactoryBean

也就是说SpringProcessEngine使用的LocalSessionFactoryBean和applicationContext.xml里面配置的LocalSessionFactoryBean类型是不一样的,所以导致空指针异常。

 

lijiejava 2013-09-04
自己写一个SpringProcessEngine类覆盖,获取hibernate4.LocalSessionFactoryBean。
http://lijiejava.iteye.com/blog/1934927
Global site tag (gtag.js) - Google Analytics