Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
avneesh Sep 25, 2012 11:40 AMHi,
When I am trying to create Local Task Service for jbpm human task using spring framework. It throwing exception.
I have a java class
TaskResourceFactory.java
public class TaskResourceFactory { private static final Logger logger = LoggerFactory.getLogger(TaskResourceFactory.class); private static TaskService taskService; private static AbstractPlatformTransactionManager transactionManager; public TaskResourceFactory(TaskService tService, AbstractPlatformTransactionManager tManager) { TaskResourceFactory.taskService = tService; TaskResourceFactory.transactionManager = tManager; } public static LocalTaskService getTaskClient(TaskService taskService, AbstractPlatformTransactionManager transactionManager) { new TaskResourceFactory(taskService, transactionManager); initializeSessionFactory(transactionManager); LocalTaskService returnBean = new LocalTaskService(taskService); return returnBean; } public static void initializeSessionFactory(AbstractPlatformTransactionManager transactionManager) { ApplicationContext ctx = AppContext.getApplicationContext(); TaskSessionSpringFactoryImpl springFactory = (TaskSessionSpringFactoryImpl) ctx.getBean("springTaskSessionFactory"); TransactionManager taskTx = new CustomDroolsSpringTransactionManager(transactionManager); springFactory.setTransactionManager(taskTx); springFactory.initialize(); } }
When springFactory.initialize() calling TaskService class it throwing error.
my applicationContext.xml is:
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:jboss/TransactionManager"/> </bean> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:jboss/datasources/RI"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="jbpm" /> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> </bean> <bean id="jpaTxMgr" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="nestedTransactionAllowed" value="true"/> </bean> <bean id="systemEventListener" class="org.drools.SystemEventListenerFactory" factory-method="getSystemEventListener" /> <bean id="taskService" class="org.jbpm.task.service.TaskService" > <property name="systemEventListener" ref="systemEventListener" /> </bean> <bean id="htEm" class="org.springframework.orm.jpa.support.SharedEntityManagerBean"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean id="htTxMgr" class="org.drools.container.spring.beans.persistence.HumanTaskSpringTransactionManager"> <constructor-arg ref="transactionManager" /> </bean> <bean id="springTaskSessionFactory" class="org.jbpm.task.service.persistence.TaskSessionSpringFactoryImpl" depends-on="taskService" > <property name="transactionManager" ref="htTxMgr" /> <property name="useJTA" value="true" /> <property name="taskService" ref="taskService" /> </bean> <bean id="taskResourceFactory" class="com.nijhazer.jbpm.quickstart.TaskResourceFactory" factory-method="getTaskClient"> <constructor-arg type="org.jbpm.task.service.TaskService" ref="taskService" /> <constructor-arg type="org.springframework.transaction.support.AbstractPlatformTransactionManager" ref="transactionManager" /> </bean>
stacktrace is:
21:00:05,071 INFO [stdout] (MSC service thread 1-1) 2012-09-25 21:00:05,068 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed 21:00:05,071 INFO [stdout] (MSC service thread 1-1) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.jbpm.task.service.local.LocalTaskService com.nijhazer.jbpm.quickstart.TaskResourceFactory.getTaskClient (org.jbpm.task.service.TaskService,org.springframework.transaction.support.AbstractPlatformTransactionManager)] threw exception; nested exception is java.lang.NullPointerException 21:00:05,071 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod (AbstractAutowireCapableBeanFactory.java:1015) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java:911) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:485) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:456) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 21:00:05,072 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) 21:00:05,073 INFO [stdout] (MSC service thread 1-1) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 21:00:05,074 INFO [stdout] (MSC service thread 1-1) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 21:00:05,075 INFO [stdout] (MSC service thread 1-1) at java.lang.Thread.run(Thread.java:662) 21:00:05,075 INFO [stdout] (MSC service thread 1-1) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.jbpm.task.service.local.LocalTaskService com.nijhazer.jbpm.quickstart.TaskResourceFactory.getTaskClient (org.jbpm.task.service.TaskService,org.springframework.transaction.support.AbstractPlatformTransactionManager)] threw exception; nested exception is java.lang.NullPointerException 21:00:05,075 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:169) 21:00:05,075 INFO [stdout] (MSC service thread 1-1) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) 21:00:05,075 INFO [stdout] (MSC service thread 1-1) ... 22 more