将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类型是不一样的,所以导致空指针异常。