我有一个 Spring MVC 3.1.1 应用程序,需要查找部署到 Weblogic 10.3.5 中的远程 EJB 3.0。
Spring 应用程序在本地服务器 VMware vFabric tc S.D.E. 内运行。 2.9, Weblogic也是本地的,由STS 3.4.0启动
我尝试了很多不同的查找方式,但错误消息是:
Name [ABC] is not bound in this Context. Unable to find [ABC]
每次尝试 ABC 都不同。
Weblogic 已安装并配置,我可以看到部署在控制台内的 EJB,这就是我在他的 JNDI 树中可以看到的内容:
AdminServer+LoginBean#it+company+project+ejb+login+LoginBeanRemote
其中每个+
都是一个树节点,名称为LoginBean#it.company.project.ejb.login.LoginBeanRemote
在 AdminServer 下,我还可以看到子树 ejb.mgmt.MEJB
,我不知道这是否是一个有用的通知。
如您所见,我想在 Spring Security 3.1.4 内为登录范围创建该 EJB。
这是远程接口(interface)的分支:
@Remote
public interface LoginBeanRemote {
public User loadUserByUsername(final String username);
}
这是类分支:
@Stateless(mappedName = "LoginBean")
public class LoginBean implements LoginBeanRemote {
@Override
public User loadUserByUsername(final String username) {
final User user = new User();
(...)
return user;
}
}
现在没有 ejb-jar.xml
也没有 weblogic-ejb-jar.xml
,但是当我使用一个或每个配置 XML 时,我已经得到了同样的消息。
现在,我不在 @Stateless
中使用 name
标记,但是当我使用它时,我收到了相同的消息。
这是客户端分支:
public class UserLogin {
public User loadUserByUsername(final String username) {
final User user = new User();
Context context = null;
final Hashtable <String, String> webLogic = new Hashtable <String, String>();
webLogic.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
webLogic.put(Context.PROVIDER_URL, "[http://localhost:7001]()"); //also used t3 and iiop
//also used SECURITY_PRINCIPAL & SECURITY_CREDENTIALS
try {
context = new InitialContext();
final LoginBeanRemote login = (LoginBeanRemote) context.lookup("LoginBean#it.postel.aos.ejb.login.LoginBeanRemote");
(...)
} catch (final NamingException ne) {
(...)
}
(...)
return user;
}
}
在生产环境中,Spring 应用程序将部署到与 EJB 模块不同的 AS 中,甚至是 Weblogic 10.3.5,因此我使用了远程 EJB。
我已经测试了 STS 内部的所有内容。
我已将 EJB 作为外部 JAR 引用到 Spring 应用程序中。
我已将 lib 文件夹中的这些文件放入我域的 Weblogic 服务器中:
LoginEjb.jar
、weblogic.jar
和 wlfullclient.jar
、
但在没有这些文件的情况下我也收到了相同的错误消息(即使我认为我不需要将 weblogic.jar
放入其中)。
我不知道是否需要一个 XML 配置(ejb-jar.xml
或 weblogic-ejb-jar.xml
),也许当我创建这些文件时犯了一些错误(现在我没有那些文件),但我也读到我可以在没有 XML 的情况下部署 EJB。
我在 Stack Overflow 上阅读了一些其他问题,但没有一个建议为我提供了解决方案。
最佳答案
这至少是错误的:
final Hashtable <String, String> webLogic = new Hashtable <String, String>();
webLogic.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
webLogic.put(Context.PROVIDER_URL, "[http://localhost:7001]()"); //also used t3 and iiop
try {
context = new InitialContext();
如果您仅使用不带参数的new InitialContext()
,则您正在执行本地查找,而不是远程查找。您需要使用您拥有的参数初始化上下文,如下所示:
final Hashtable <String, String> webLogic = new Hashtable <String, String>();
webLogic.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
webLogic.put(Context.PROVIDER_URL, "http://localhost:7001"); //also used t3 and iiop
try {
context = new InitialContext(webLogic); // <--- note this
关于java - 远程 EJB 3.0 查找(STS 3.4.0、Weblogic 10.3.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19785493/