【发布时间】:2014-04-03 13:13:48
【问题描述】:
我正在尝试使用完全相同的 bean 实现从一个部署到另一个部署进行查找。它基本上是一个消费者/生产者设置,在两台机器上的两个部署中使用相同的 bean。
ear
ejb-api
com.example.bean
ConsumerBean
ProducerBean
ejb-jar
com.example.bean
ConsumerBeanRemote
ProducerBeanRemote
ProducerBeanRemote 应该查找 ConsumerBeanRemote 并调用它的公共方法。
我们的机器是这样通信的:
(Machine A) ProducerBeanRemote --> (Machine B) ConsumerBeanRemote
(Machine A) ProducerBeanRemote --> (Machine C) ConsumerBeanRemote
(Machine A) ProducerBeanRemote --> (Machine D) ConsumerBeanRemote
你懂的……
所以问题是,它不起作用。我尝试使用 jboss-as-ejb-client 库进行手动查找,但这不起作用,因为 JBoss 在启动其容器时锁定了 EJB 选择器(而且我敢打赌,规范对 Java EE 中的手动查找有话要说环境)。接下来我尝试使用 Spring 的功能进行查找,但无济于事。
我们使用的是 JBoss Application Server 7.1.1.Final。
我敢打赌,必须有一种方法来完成我的设置,我非常感谢社区提供的任何帮助。
更新:
要从 ProducerBeanRemote 连接到 ConsumerBeanRemote,我们需要能够在运行时通过配置指定远程 InitialContext。
Properties properties = new Properties();
properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
properties.put("remote.connections", "default");
properties.put("remote.connection.default.host", "remote-host");
properties.put("remote.connection.default.port", "4447");
properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(properties);
ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
EJBClientContext.setSelector(ejbClientContextSelector);
StatelessEJBLocator<T> locator = new StatelessEJBLocator<>(viewType, appName, moduleName, beanName, distinctName);
return EJBClient.createProxy(locator);
产生的异常是
java.lang.SecurityException: EJB client context selector may not be changed at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)
我们知道这个异常是因为https://issues.jboss.org/browse/AS7-2998而抛出的,所以问题仍然存在:我们如何才能以一种干净且可配置的方式远程调用相同的bean?
【问题讨论】:
-
“它不起作用”只有在只有一个问题要谈,因此只有一个解决方案要给出时才是一个有效的问题描述。
-
@Gimby 我很乐意详细介绍,你需要知道什么?
-
你开始的错误!
-
我更新了我的问题。
-
这个问题不应该得到公认的答案,因为它来自 Alexander Muller。有一种方法可以做到这一点,接受一个相当于“idk”的答案只是意味着 StackOverflow 社区的其他人跳过了这个问题,因为他们认为它已经得到了回答,而其他所有想要学习的人都因此而受苦.包括我自己,因为我想了解 Remote 在服务器间通信方面的工作原理。
标签: java spring jboss7.x java-ee-6 ejb-3.1