Spring context initialization fails in WorkItemHandler.executeWorkItem()

50 views
Skip to first unread message

Ross Adamson

unread,
Jun 7, 2018, 11:43:42 PM6/7/18
to jBPM Development
I have a custom WorkItemHandler which initializes a Spring context using
new ClassPathXmlApplicationContext("classpath:workflow-beans.xml")

At first, the context failed to initialize due to Spring not being able to find the workflow-beans.xml file at all. So, I found out that you can pass in a classLoader into the custom WorkItemHandler constructor and use that passed in classLoader to initialize Spring. So I did that:
               context = new ClassPathXmlApplicationContext("classpath:workflow-beans.xml") {
                    @Override
                    protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
                        super.initBeanDefinitionReader(reader);

                        reader.setBeanClassLoader(passedInClassLoader);
                        setClassLoader(passedInClassLoader);
                    }
                };

My workflow-beans.xml file is:

When using the passed in classLoader to initialize the Spring context, it fails with an error like so:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/data/maven/repositories/kie/com/company/project/my-workflow-kjar/18.05.1-SNAPSHOT/my-workflow-18.05.1-SNAPSHOT.jar!/com/company/workflow/registration/MessageConsumer.class]; nested

 exception is java.io.FileNotFoundException: JAR entry com/company/workflow/registration/MessageConsumer.class not found in /data/maven/repositories/kie/com/company/project/my-workflow/18.05.1-SNAPSHOT/my-workflow-18.05.1-SNAPSHOT.jar


Now, I can see that the class it fails to find is there in the JAR, but the path it's looking for is slightly incorrect -- it's missing "project" after "com/company/". It should be looking for
!/com/company/project/workflow/registration/MessageConsumer.class
instead of
!/com/company/workflow/registration/MessageConsumer.class

Do you know why it would be dropping part of the package name from the path of the class it's searching for?

Also, in general, what is the best way to use Spring inside custom WorkItemHandlerS?

Maciej Swiderski

unread,
Jun 8, 2018, 5:56:14 AM6/8/18
to Ross Adamson, jBPM Development
I am not aware of anything that would drop package names or manipulate them in anyway.  could it be there are some references (some leftovers) to that package on the classpath?

Maciej

-- 
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-development/6669a5b7-7b9e-4ec1-ac63-1a6568cc9d77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ross Adamson

unread,
Jun 15, 2018, 1:34:17 PM6/15/18
to jBPM Development
I was able to get passed the exception by removing the MessageConsumer class out of the KJAR (I ended up not needing it anyway). Once my KJAR had zero java class files in it, the Spring initialization worked.

Ross
Maciej

To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-development+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages