Unable to use BeanManager.getReference() to find a bean by its Interface in EAP 6.4

Latest response

Hi,
I'm working on migrating our JBoss 6.1.0.Final system to EAP 6.4, and
I'm having a problem with using the BeanManager to find beans by using the Interface the bean implements.
This is working fine with JBoss 6.1 but I am unable to make it work with EAP 6.4.

Given

@Local
public interface Ia {
}
@Stateless
public class A implements Ia {
}


We are calling the beanManager like this:

Set<Bean<?>> beans = beanManager.getBeans(Ia.class);
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> context = beanManager.createCreationalContext(bean);
beanManager.getReference(bean, beanClass, context);

and get back a null.

Debugging the code I find that it boils down to this piece of code in the Reflections class:

public boolean matches(TypeHolder otherTypeHolder) {
return getBoxedRawType().equals(otherTypeHolder.getBoxedRawType()) && areActualTypeArgumentsAssignableFrom(otherTypeHolder.getActualTypeArguments());
}

where I see ' (java.lang.Class) class a.A' being compared to ' (java.lang.Class) interface a.Ia'
and of course not matching,

I'm pretty new to CDI so I'm hoping there is an easy answer?

Thanks

George

Responses

Can you try changing the code to this and let me know if that makes a difference?

beanManager.getBeans(Ia.class).iterator().next()

Thanks
Mustafa

Actually, along with that change I think you need to also change the beanManager.getReference(bean, beanClass, context); . How are you getting the beanClass?

Change it to the following:

beanManager.getReference(bean, bean.getBeanClass(), context);

Using the iterator made no difference:
I should have included the error message from the console:

WELD-001305 The given type class a.A is not a type of the bean Session bean [class a.A with qualifiers [@Default @Any]; local interfaces are [Ia]

beanClass comes from bean.getBeanClass()

You may need to raise a support case if you don't have any luck with the above suggestions. The error seems to be similar to what is mentioned here [1]. Have you tried this on EAP 6.2.0 just to see if it's working on any versions between EAP 6.1.0 and before EAP 6.4.0?

[1] https://access.redhat.com/solutions/662473

It works with up to and including EAP 6.0.0.GA. It fails with EAP 6.0.1.GA and above.

Weld went from 1.1.8 to 1.1.10