jsr366-experts@javaee-spec.java.net

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

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Thu, 05 Mar 2015 14:55:40 -0800

Jason Greene wrote on 03/05/2015 02:45 PM:
>
>> 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.

Well, I never said there weren't bugs in the RI! :-)

Essentially the same thing works fine for me if I use a Servlet instead
of an EJB. Why does it work in one case and not the other? I have no
idea. If you change your example to use java:app, does it work?