简体   繁体   English

从不同的模块但相同的应用程序注入@EJB

[英]injecting @EJB from different module but same application

I have an application on a Weblogic Server.我在 Weblogic 服务器上有一个应用程序。 I have issues with injecting an EJB from my RESTWEBservice into my SOAPwebservice.我在将 EJB 从我的 RESTWEB 服务注入到我的 SOAPweb 服务时遇到了问题。 This application have several modules.这个应用程序有几个模块。 Only Three of them is important now.现在只有三个是重要的。

The deployment looks like this:部署如下所示:

Application应用

  • API (JAR) API (JAR)
  • SOAPWebService (WAR) SOAPWebService (WAR)
  • RESTWebService(WAR) RESTWeb 服务(战争)

Both Webservices have the API built into them.两个 Web 服务都内置了 API。 Here is the important part of the classes.这是课程的重要部分。 My RestWebservice EJB I want to inject:我要注入的 RestWebservice EJB:

@Local(EJBSOAPinterface.class)
@Stateless(mappedName = "RESTCLASS", name="RESTCLASS")
public class RESTCLASS implements EJBSOAPinterface{...}

The interface in the API which both modules use:两个模块使用的 API 中的接口:

@Local
public interface EJBSOAPinterface{....}

The SOAP webserviceModule who wants to inject the EJB想要注入 EJB 的 SOAP webserviceModule

public SOAPCLASS {
@EJB(lookup="JNDINAME..")
EJBSOAPinterface ejb;
......}

I have tried to use both @Local and @Remote on both interface and the EJB.我尝试在接口和 EJB 上同时使用 @Local 和 @Remote。 it doesn't work.它不起作用。

I have tried this to inject the EJB as well我也试过用这个来注入 EJB

public SOAPCLASS{
@EJB(name="RESTCLASS")
EJBSOAPinterface ejb;
.....}

it doesn't work either.它也不起作用。 The problem is that my SOAPCLASS wont deploy because of that injection.问题是我的 SOAPCLASS 由于注入而无法部署。 I get different Exceptions depending on how I do it.根据我的操作方式,我会收到不同的异常。 But currently I get但目前我得到

java.lang.InstantiationException: Error creating bean with name: "....." ..... Dependency injection failure: can't find the bean definition about class interface "....." java.lang.InstantiationException: Error created bean with name: "....." ..... 依赖注入失败:找不到关于类接口 "....." 的 bean 定义

I am kind of new to java.我对java有点陌生。

UPDATE - SOLVED.更新 - 已解决。 I did put @Remote instead of @Local on the interface.我确实在界面上放置了@Remote 而不是@Local。 And the same thing on the EJB itself. EJB 本身也是如此。 The JNDI name i had was correct (RESTCLASS#INTERFACEPACKETNAME.EJBSOAPINTERFACE).我的 JNDI 名称是正确的(RESTCLASS#INTERFACEPACKETNAME.EJBSOAPINTERFACE)。

The problem was that when i deploy the application on the WLServer i deployed the SOAPCLASS Before the RESTCLASS.问题是,当我在 WLServer 上部署应用程序时,我在 RESTCLASS 之前部署了 SOAPCLASS。 Which means that it couldnt find any JNDI name yet.这意味着它还找不到任何 JNDI 名称。 Because it wasnt built yet.因为还没建好。 I just changed the deploymentorder of those 2 and it worked instantly.我只是更改了这两个的部署顺序,它立即生效。 Thanks!谢谢!

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

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