我应该使用什么JNDI名称来查找使用Spring Boot部署在websphere中的远程接口



我在websphere8.5.5中部署了一个远程接口,我想在spring引导应用程序中查找它。我在春季启动中创建了与公共接口RMI类似的接口。我也使用了SimpleRemoteStatelessSessionProxyFactoryBean,但返回的代理是null,它在proxy.invokeMethod()中抛出了null指针

@Configuration
public class Config {
private static final String INITIAL_CONTEXT_FACTORY = "com.ibm.websphere.naming.WsnInitialContextFactory";
private static final String PROVIDER_URL = "corbaname:iiop:localhost:2809/NameServiceServerRoot";
@Primary
@Bean
public static AdminService adminService() {
Properties jndiProps = new Properties();
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
properties.put(Context.PROVIDER_URL, PROVIDER_URL);
SimpleRemoteStatelessSessionProxyFactoryBean factory = new SimpleRemoteStatelessSessionProxyFactoryBean();
factory.setJndiEnvironment(jndiProps);
factory.setJndiName("java:global/[AppName]/[ModuleName]/ejb/[BeanName]![RemoteInterface]");
factory.setBusinessInterface(AdminService.class);
factory.setResourceRef(true);
AdminService proxy = (AdminService) factory.getObject();
try {
proxy.invokeMethod();
}catch(RemoteException e) {
e.printStackTrace();
}
return proxy;       
}
}

现在它抛出了这个错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AdminService' defined in class path resource [...Config.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [...AdminService]: Factory method 'adminEJBService' threw exception; nested exception is javax.naming.NameNotFoundException: Name [global/[AppName]/[ModuleName]/ejb/[BeanName]![RemoteInterface] is not bound in this Context. Unable to find [global].

必须用实际名称替换[]中的所有内容,因此不是[AppName],而是MyApp等。如果不确定,可以通过在WebSphere 8.5.5服务器的SystemOut.log文件中查找消息CNTR0167I来确定确切的查找字符串。例如,实际消息如下所示:

CNTR0167I: The server is binding the javax.management.j2ee.ManagementHome interface of the Management enterprise bean in the mejb.jar module of the ManagementEJB application.  The binding location is: java:global/ManagementEJB/mejb/Management!javax.management.j2ee.ManagementHome

最新更新