How to insert one EJB 3.1 into another EJB

I am developing a simple application where one EJB must be added to another. I am developing at the IDEA Jetbrains IDE. But after I make the @EJB annotation in the local Ejb statjet class, my IDE allocates it with an error: EJB '' with the component interface “ApplicationController” was not found.

Can anyone say why?

+3
source share
2 answers

Injecting an EJB reference into another EJB can be accomplished using annotation @EJB. Here is an example taken from Including another example of EJBs from the OpenEJB documentation:

The code

beans (DataReader DataStore), , @EJB beans, bean

DataStore bean

Bean

@Stateless
public class DataStoreImpl implements DataStoreLocal, DataStoreRemote{

  public String getData() {
      return "42";
  }

}

-

@Local
public interface DataStoreLocal {

  public String getData();

}

-

@Remote
public interface DataStoreRemote {

  public String getData();

}

DataReader bean

Bean

@Stateless
public class DataReaderImpl implements DataReaderLocal, DataReaderRemote {

  @EJB private DataStoreRemote dataStoreRemote;
  @EJB private DataStoreLocal dataStoreLocal;

  public String readDataFromLocalStore() {
      return "LOCAL:"+dataStoreLocal.getData();
  }

  public String readDataFromRemoteStore() {
      return "REMOTE:"+dataStoreRemote.getData();
  }
}

@EJB DataStoreRemote DataStoreLocal. EJB ref . beans, , beanName :

@EJB(beanName = "DataStoreImpl") 
private DataStoreRemote dataStoreRemote;

@EJB(beanName = "DataStoreImpl") 
private DataStoreLocal dataStoreLocal;

-

@Local
public interface DataReaderLocal {

  public String readDataFromLocalStore();
  public String readDataFromRemoteStore();
}

( - ).

, , .

+13

, IntelliJ IDEA. :

EJB Facet ( a > )

+5

Source: https://habr.com/ru/post/1761743/


All Articles