Topic
  • 6 replies
  • Latest Post - ‏2013-03-25T13:26:27Z by SystemAdmin
SystemAdmin
SystemAdmin
37422 Posts

Pinned topic @Resource in @AlterNative Bean

‏2013-03-22T10:59:55Z |
I have a Bean annotated by @AlterNative, And in this bean, there is a private field annotated by
@Resource, like this

@Alternative
public class TestServiceImpl implements TestServcie {

@Resource
protected TransactionManager transactionManager;

...

I also have another implement without @AlterNative Annotation and without transactionManager field.

And I do not enable the @Alternative TestServiceImpl in all the beans.xml.

When I deploy this. I get a error message

CWNEN0044E: A resource reference binding could not be found for the following resource references TestServiceImpl/transactionManager

but it can be deploied without error in Tomee and GlassFish.

Any Idea?
Updated on 2013-03-25T13:26:27Z at 2013-03-25T13:26:27Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-22T11:55:35Z  
    > 5EYQ_Zhong_Guan wrote:
    > @Alternative
    > public class TestServiceImpl implements TestServcie {
    >
    > @Resource
    > protected TransactionManager transactionManager;
    >
    > And I do not enable the @Alternative TestServiceImpl in all the beans.xml.
    > CWNEN0044E: A resource reference binding could not be found for the following resource references TestServiceImpl/transactionManager

    Scanning for EE style injection (@EJB, @Resource) doesn't take into account whether a bean is elligible for CDI/@Inject Injection. For example, any bean in use outside of CDI can also be an @Alternative but still new'ed up, so it needs to be scanned/injected for EE.

    --
    Eric Covener
    IBM HTTP Server and Apache Development
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-23T08:27:18Z  
    > 5EYQ_Zhong_Guan wrote:
    > @Alternative
    > public class TestServiceImpl implements TestServcie {
    >
    > @Resource
    > protected TransactionManager transactionManager;
    >
    > And I do not enable the @Alternative TestServiceImpl in all the beans.xml.
    > CWNEN0044E: A resource reference binding could not be found for the following resource references TestServiceImpl/transactionManager

    Scanning for EE style injection (@EJB, @Resource) doesn't take into account whether a bean is elligible for CDI/@Inject Injection. For example, any bean in use outside of CDI can also be an @Alternative but still new'ed up, so it needs to be scanned/injected for EE.

    --
    Eric Covener
    IBM HTTP Server and Apache Development
    Thank you for the clear answer.
    I am going to look for another way to handle this situation.
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-23T14:09:18Z  
    Thank you for the clear answer.
    I am going to look for another way to handle this situation.
    I found there is a way to ignore the Annotation Scanning by add
    Ignore-Scanning-Packages : xxx.xx.xx in META-INF/MANIFEST.MF .

    I have not the test Env right now.
    My question is can this package(xxx.xx.xx) be in jar file which
    is at WEB-INF/lib ?

    Thanks
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-25T06:17:45Z  
    I found there is a way to ignore the Annotation Scanning by add
    Ignore-Scanning-Packages : xxx.xx.xx in META-INF/MANIFEST.MF .

    I have not the test Env right now.
    My question is can this package(xxx.xx.xx) be in jar file which
    is at WEB-INF/lib ?

    Thanks
    I have tested the Ignore-Scanning-Packages setting.
    If I put the Ignore-Scanning-Packages setting in the
    profile_root/amm.filter.properties file, it works well.
    But if I put this setting to the META-INF\MANIFEST.MF of
    WAR file. like

    Manifest-Version: 1.0
    Class-Path:
    Ignore-Scanning-Packages: xxx.xx.xx
    It doesn't work.
    It is still the error message of
    CWNEN0044E: A resource reference binding could not be found for the following resource references...

    By the way, The xxx.xx.xx package is in the jar file at WEB-INF/lib.

    Is my setting of the MANIFEST.MF right?

    Thanks for any advice
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-25T07:34:04Z  
    a new related question
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: @Resource in @AlterNative Bean

    ‏2013-03-25T13:26:27Z  
    a new related question
    Finally, I add that setting to the MANIFEST.MF in Jar file. It works fine....