0

I have a problem with my EJB:

public class EntryResponseBuilder extends BaseResponseBuilder {
@EJB
private ApplicationCustomerCache applicationCustomerCache; //null

I have something like this in class that returns a JSON response.

@Singleton
@Startup
public class ApplicationCustomerCache {
    @EJB
    CustomerDao customerDao;
    private Map<Integer, Customer> customerMap;
    private Map<Integer, List<Customer>> applicationToCustomersMap;
    private static Logger log = Logger.getLogger(ApplicationCustomerCache.class);

    @PostConstruct
    public void initialize() {
        try {
            get();
        } catch (Exception e) {
            log.error("ApplicationCustomerCache.init()", e);
        }
    }

    private void get() throws SQLException {

And its working fine, except that when I try to get injection in EntryResponseBuilder, it's empty. One function before, it inject, where I have class with @Stateless. I've searched in Google, but I can not find any solution.

javapapo
  • 1,342
  • 14
  • 26
qusqui21
  • 170
  • 1
  • 12

2 Answers2

2

Your dealing with two issues here:

  1. Your're trying to inject an instance of a bean on a POJO, which is not managed by the container;
  2. What's the EJB spec that you're following?

For both of them, I think the following answers can help you:

Community
  • 1
  • 1
António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
0

I solved it by using InitialContext()

ApplicationCustomerCache applicationCustomerCache = (ApplicationCustomerCache) new InitialContext().lookup("java:comp/ApplicationCustomerCache");
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
qusqui21
  • 170
  • 1
  • 12