timothyclifford
timothyclifford

Reputation: 6959

Spring Boot JNDI CommonJ resource

Trying to get WorkManagers working with CommonJ in a Spring Boot app, hosted in TomEE.

Currently have the following configuration:

Tomcat context.xml

<Context>
  <Resource name="myWorkManager"
    auth="Container"
    type="commonj.work.WorkManager"
    factory="de.myfoo.commonj.work.FooWorkManagerFactory"
    maxThreads="5" />
  <ResourceLink
    name="myWorkManager"
    global="myWorkManager"
    type="commonj.work.WorkManager" />
</Context>

Spring app web.xml

<resource-ref>
    <res-ref-name>myWorkManager</res-ref-name>
    <res-type>commonj.work.WorkManager</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

This is currently throwing the following exception when the app loads:

Caused by: org.springframework.jndi.TypeMismatchNamingException: Object of type [class de.myfoo.commonj.work.FooWorkManager] available at JNDI location [java:comp/env/myWorkManager] is not assignable to [commonj.work.WorkManager]
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:182)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.scheduling.commonj.WorkManagerTaskExecutor.afterPropertiesSet(WorkManagerTaskExecutor.java:110)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 53 more

I have the CommonJ jars downloaded from http://commonj.myfoo.de/install.shtml in my Tomcat lib directory.

I feel like I'm getting pretty close but slightly puzzled by this exception.

Any help would be much appreciated.

UPDATE

If I remove the two CommonJ jars from TomEE lib folder, I get this exception

Caused by: java.lang.ClassNotFoundException: commonj.work.WorkManager

Which is what I would expect.

If I remove the factory property from the resource element I get:

Caused by: org.springframework.jndi.TypeMismatchNamingException: Object of type [class org.apache.openejb.core.ivm.naming.IvmContext] available at JNDI location [java:comp/env/wm/default] is not assignable to [commonj.work.WorkManager]

Upvotes: 2

Views: 3234

Answers (1)

Sergey
Sergey

Reputation: 370

Im encounter with same issue, when try to start my app locally in maven-jetty-plugin. M. Deinum comment was very helpful. This error happens if you have lib jar in shared lib of your Application Server and in your WEB-INF/lib folder of web application, because server use one jar to create resource (parent classloader), but application use self jar(child classloader) and it two different classes hierarchy, so FooWorkManager cant be cast to WorkManager.

Upvotes: 1

Related Questions