jsr366-experts@javaee-spec.java.net

[jsr366-experts] Re: Compatibility Problems with MR Resource Annotation Widening

From: Jason Greene <jason.greene_at_redhat.com>
Date: Thu, 5 Mar 2015 16:45:34 -0600

> On Mar 5, 2015, at 4:19 PM, Bill Shannon <bill.shannon_at_oracle.com> wrote:
>
> Show me.
>
> I have a CDI bean that's @Injected in to a servlet, and the CDI bean declares
> @Resource injected fields. The fields are injected into the bean and the bean
> is injected into the servlet. It works fine.

Create a Base.java:

@ApplicationScoped
public class Base {

  @Resource(name="java:module/env/myresource", lookup="java:comp/DefaultDataSource")
  DataSource ds;
}

Then an SLSB:

@Stateless
public class SLSB {
  @Inject Base base;

  @javax.annotation.PostConstruct
  public void setup() {
      System.out.println("========= BASE is = " + base.ds);
  }

  public void doSomething() throws Exception {
      System.out.println("========= BASE is = " + base.ds);
  }
}

Package them up in an ejb jar.

I get null (using the EE7 RI update 1).

It certainly could work, but only if you *know* Base.java is a CDI managed. To use an example, if there was an @Veteod on Base, it should not work.

--
Jason T. Greene
WildFly Lead / JBoss EAP Platform Architect
JBoss, a division of Red Hat