5 Replies Latest reply on Sep 27, 2012 1:20 PM by Kris Verlaenen

    Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]

    Avneesh Sisodia Newbie

      Hi,

      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
      
      
        • 1. Re: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
          Kris Verlaenen Master

          Hi,

           

          I wasn't able to reproduce the exact issue (due to some missing classes and not having the same context setup), but here's an example that successfully loads the human task service:

           

                  ClassPathXmlApplicationContext context =

                      new ClassPathXmlApplicationContext("spring-conf.xml");

                 

                  TaskSessionSpringFactoryImpl springFactory =

                      (TaskSessionSpringFactoryImpl) context.getBean("springTaskSessionFactory");      

                  springFactory.initialize();

                         

                  org.jbpm.task.service.TaskService internalTaskService =

                      (org.jbpm.task.service.TaskService) context.getBean("taskService");

                  TaskService taskService = new LocalTaskService(internalTaskService);

                  System.out.println("Done setting up " + taskService);

           

          With the following spring configuration file

           

          <?xml version="1.0" encoding="UTF-8"?>

          <beans xmlns="http://www.springframework.org/schema/beans"

                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                 xmlns:jbpm="http://drools.org/schema/drools-spring"      

                 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

                                     http://drools.org/schema/drools-spring org/drools/container/spring/drools-spring-1.5.0.xsd">

           

            <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

              <property name="driverClassName" value="org.h2.Driver"/>

              <property name="url" value="jdbc:h2:tcp://localhost/~/jbpm-db"/>

              <property name="username" value="sa"/>

              <property name="password" value=""/>

            </bean>

             

            <bean id="jbpmEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

              <property name="dataSource" ref="dataSource"/>

              <property name="persistenceUnitName" value="org.jbpm.persistence.jpa.local"/>

            </bean>

           

            <bean id="jbpmTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">

              <property name="entityManagerFactory" ref="jbpmEMF"/>

              <property name="nestedTransactionAllowed" value="false"/>

            </bean>

           

            <bean id="htTxMgr" class="org.drools.container.spring.beans.persistence.HumanTaskSpringTransactionManager">

              <constructor-arg ref="jbpmTxManager" />

            </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="springTaskSessionFactory" class="org.jbpm.task.service.persistence.TaskSessionSpringFactoryImpl" depends-on="taskService" >

              <property name="entityManagerFactory" ref="jbpmEMF" />

              <property name="transactionManager" ref="htTxMgr" />

              <property name="useJTA" value="true" />

              <property name="taskService" ref="taskService" />

            </bean>

           

          </beans>

           

          Hope this helps.

           

          Kris

          • 2. Re: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
            Avneesh Sisodia Newbie

            Thanks krisv,

            When I did changes as you told in previuos post. I am facing an error.

             

            in spring-config file code is:

             

                 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
                    <property name="url" value="jdbc:sqlserver://IITC-SRV-DB01:1433=RI" />
                    <property name="username" value="***" />
                    <property name="password" value="******" />
                </bean>
            
                <bean id="jbpmEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                    <property name="dataSource" ref="dataSource" />
                    <property name="persistenceUnitName" value="org.jbpm.persistence.jpa.local" />
                </bean>
            
                 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
                    <property name="transactionManagerName" value="java:jboss/TransactionManager"/>
                </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>
            

             

            Here is 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");      
                    springFactory.initialize();
                    TaskService internalTaskService = (TaskService) ctx.getBean("taskService"); 
                    LocalTaskService taskService = new LocalTaskService(internalTaskService); 
                    System.out.println("Done setting up " + taskService)
                  }
            }
            

            when springFactory.initialize() is called it throws exception:

             

            15:51:36,660 INFO  [stdout] (MSC service thread 1-2) 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.getTaskClien
            t(org.jbpm.task.service.TaskService,org.springframework.transaction.support.AbstractPlatformTransactionManager)] 
            threw exception; nested exception is java.lang.RuntimeException: Operation failed
            

             

            anything else I am missing to be change to get out from this exception krisv,

            complete exception is attached:

            Please suggest me.

            • 3. Re: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
              Kris Verlaenen Master

              Hi,

               

              This definitely seems to be a different error:

              Caused by: java.lang.IllegalArgumentException: Named query not found: UnescalatedDeadlines

               

              It's not picking up the query, which is defined in the Taskorm.xml file:

              https://github.com/droolsjbpm/jbpm/blob/master/jbpm-human-task/jbpm-human-task-core/src/main/resources/META-INF/Taskorm.xml#L938

              This config file should be part of the jbpm-human-task-core jar

               

              In your persistence.xml, do you have a reference to this config file (so it knows to load it), something like:

              <mapping-file>META-INF/Taskorm.xml</mapping-file>

               

              Looking at your server log, it seems it's trying to load it, but fails:

              15:44:18,871 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH00360:Unable to resolve mapping file [classpath:Taskorm.xml]

              Could it be that you missed the META-INF folder?

               

              Kris

              • 4. Re: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
                Avneesh Sisodia Newbie

                Hi Kris,

                I put that file Taskorm.xml in META-INF and it is included in persistence.xml file.

                Now it is showing this error:

                 

                20:34:55,227 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH00204:Processing PersistenceUnitInfo [
                    name: jbpm
                    ...]
                20:34:55,267 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.persistenceunit."jbpm-spring-quickstart.war#jbpm": 
                org.jboss.msc.service.StartException in service jboss.persistenceunit."jbpm-spring-quickstart.war#jbpm": Failed to start service
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1786)
                    at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_25]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_25]
                    at java.lang.Thread.run(Thread.java:662) [:1.6.0_25]
                Caused by: org.hibernate.InvalidMappingException: Unable to read XML
                    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:102)
                    at org.hibernate.ejb.Ejb3Configuration.addXMLEntities(Ejb3Configuration.java:724)
                    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:593)
                    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
                    at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:170)
                    at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:80)
                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
                    ... 4 more
                Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: 
                org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
                    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
                    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)
                    ... 10 more
                
                • 5. Re: Error creating bean with name 'taskResourceFactory' defined in class path resource [META-INF/spring/applicationContext.xml]
                  Kris Verlaenen Master

                  "org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory" can only happen if you have conflicting dom4j jars in your classpath somewhere.  So it's likely you have either multiple versions of this jar in your application, or one in your application and for example one in the server lib folder.

                   

                  Kris