简体   繁体   English

使用Spring Boot和WebSphere 8.5.5进行远程EJB查找

[英]Remote EJB lookup using Spring Boot and WebSphere 8.5.5

I have a batch application using Spring Batch, and I'm using Spring Boot as well. 我有一个使用Spring Batch的批处理应用程序,我也使用Spring Boot。 This application needs to do Remote EJB lookups to load some informations from the application server. 此应用程序需要执行远程EJB查找以从应用程序服务器加载一些信息。 Until now we were using JBoss EAP 6.1. 到目前为止,我们使用的是JBoss EAP 6.1。 My pom.xml contains a profile specific for JBoss and I was using the following dependency: 我的pom.xml包含一个特定于JBoss的配置文件,我使用以下依赖项:

<dependency>
    <groupId>org.jboss.as</groupId>
    <artifactId>jboss-as-ejb-client-bom</artifactId>
    <version>7.2.0.Final</version>
    <type>pom</type>
</dependency>

Now we need to migrate this application to WebSphere 8.5.5. 现在我们需要将此应用程序迁移到WebSphere 8.5.5。 I've created a new maven profile in my pom.xml with the following dependencies for Remote EJB Lookup on WebSphere. 我在我的pom.xml中创建了一个新的maven配置文件,其中包含WebSphere上的远程EJB查找的以下依赖项。

<dependency>
    <groupId>com.ibm.ws</groupId>
    <artifactId>com.ibm.ws.ejb.thinclient</artifactId>
    <version>8.5.0</version>        
    <type>pom</type>
</dependency>

<dependency>
    <groupId>com.ibm.ws</groupId>
    <artifactId>com.ibm.ws.orb</artifactId>
    <version>8.5.0</version>        
    <type>pom</type>
</dependency>

Of course I've already installed this jars in my maven local repository. 当然我已经在我的maven本地存储库中安装了这个jar。

Trying to execute the batch again, after configuring all the JNDI properties, Initial Context factory pointing to "com.ibm.websphere.naming.WsnInitialContextFactory" and Provider URL to "corbaloc:iiop:localhost:2817", I got the following exception: 在配置所有JNDI属性后,尝试再次执行批处理,初始上下文工厂指向“com.ibm.websphere.naming.WsnInitialContextFactory”,提供程序URL指向“corbaloc:iiop:localhost:2817”,我得到以下异常:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [br.com.cpqd.components.security.api.user.SecurityUser]: Factory method 'securityUserEjb' threw exception; nested exception is javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 27 common frames omitted
Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.init(InitialContext.java:242)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)
    at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
    at br.com.batch.common.BatchCommonConfig.securityUserEjb(BatchCommonConfig.java:101)
    at br.com.batch.common.BatchCommonConfig$$EnhancerBySpringCGLIB$$e2167a67.CGLIB$securityUserEjb$4(<generated>)
    at br.com.cpqd.saf.events.batch.common.BatchCommonConfig$$EnhancerBySpringCGLIB$$e2167a67$$FastClassBySpringCGLIB$$30b25502.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
    at br.com.batch.common.BatchCommonConfig$$EnhancerBySpringCGLIB$$e2167a67.securityUserEjb(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 28 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
    ... 51 common frames omitted

Ok, the class has not being found. 好的,这个班还没找到。 Trying to figure out the problem, I've changed the dependency type of WebSphere libs from "pom" to "jar". 试图找出问题,我已经将WebSphere库的依赖类型从“pom”更改为“jar”。

Now, I'm getting the following exception: 现在,我得到以下异常:

(Sorry about this Portuguese text, but the error code may help) (抱歉这个葡萄牙语文本,但错误代码可能有帮助)

**NMSV0307E**: Um nome de URL java: foi utilizado, mas a Nomenclatura não foi configurada para manipular nomes de URL java:. A causa provável é um erro do usuário ao tentar especificar um nome de URL java: em um cliente não J2EE ou no ambiente do servidor. Emitindo ConfigurationException.

2016-06-06 14:43:18.952  WARN 18856 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor': Invocation of init method failed; nested exception is javax.validation.ValidationException: Could not create Configuration.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:199)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at br.com.cpqd.saf.events.batch.BatchProcessingBootstrap.main(BatchProcessingBootstrap.java:62)
Caused by: javax.validation.ValidationException: Could not create Configuration.
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:175)
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223)
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$Jsr303ValidatorFactory.run(ConfigurationPropertiesBindingPostProcessor.java:381)
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.afterPropertiesSet(ConfigurationPropertiesBindingPostProcessor.java:174)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 12 common frames omitted
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:173)
    ... 17 common frames omitted

Googling the error message and reading lots of sites, I think that for some reason Spring Boot is not allowing the embeddable EJB container provided by the com.ibm.ws.ejb.thinclient jar to start, but I'm not sure. 谷歌搜索错误消息和阅读大量的网站,我认为由于某种原因,Spring Boot不允许com.ibm.ws.ejb.thinclient jar提供的可嵌入EJB容器启动,但我不确定。

Does anyone already tried to do that? 有没有人试过这样做?

The IndexOutOfBoundsException is the (poor) exception thrown by javax.validation.Validation when the API is available on the classpath (likely com.ibm.ws.ejb.thinclient JAR) but an implementation provider is not. 当API在类路径上可用时(可能是com.ibm.ws.ejb.thinclient JAR),但是实现提供程序不可用时, IndexOutOfBoundsException是javax.validation.Validation抛出的(差)异常。 According to the Spring documentation , the ConfigurationPropertiesBindingPostProcessor class attempts to use the javax.validation API when it is available on the classpath. 根据Spring文档ConfigurationPropertiesBindingPostProcessor类在类路径上可用时尝试使用javax.validation API。

I don't know Spring Boot well enough to know if there's a way to disable your behavior, so my best suggestion would to also include a javax.validation implementation on your classpath. 我不太清楚Spring Boot是否有办法禁用你的行为,所以我最好的建议是在你的类路径中包含一个javax.validation实现。 For example, you could also include the com.ibm.ws.jpa.thinclient JAR. 例如,您还可以包含com.ibm.ws.jpa.thinclient JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM