-
1. Re: How to get Produces bean instance in weld-1.0.2-snapshot
pmuir May 21, 2010 1:09 PM (in response to alin.heyoulin.qq.com)Bug, please report in JIRA.
-
2. Re: How to get Produces bean instance in weld-1.0.2-snapshot
alin.heyoulin.qq.com Jun 9, 2010 10:31 PM (in response to alin.heyoulin.qq.com)So i change to: Set<Bean<?>> beans = manager.getBeans("mybean"); Bean<?> sourceBean = beans.iterator().next(); manager.getReference(sourceBean, Object.class, manager.createCreationalContext(sourceBean)); WELD-001305 The given type class java.lang.Object is not a type of the bean org.jboss.weld.bean-flat-ProducerMethod-com.yofc.jcdi.produces.ProducesUtil.method getUserInfo() How can i do?
-
3. Re: How to get Produces bean instance in weld-1.0.2-snapshot
pmuir Jul 21, 2010 7:30 AM (in response to alin.heyoulin.qq.com)Ok, show the source of mybean.
-
4. Re: How to get Produces bean instance in weld-1.0.2-snapshot
alin.heyoulin.qq.com Jul 21, 2010 9:47 AM (in response to alin.heyoulin.qq.com)public class ProducesUtil {
@Produces @SessionScoped @Named(myBean
)
UserInfo getUserInfo()
{
SpringUser springUser=(SpringUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return new UserInfo(springUser.getUsername(),springUser.getName(),springUser.getPassword(),springUser.getRoles(),springUser.getRights());
}
} -
5. Re: How to get Produces bean instance in weld-1.0.2-snapshot
swd847 Jul 21, 2010 8:47 PM (in response to alin.heyoulin.qq.com)From the javadoc of Bean.getBeanClass:
/** * The bean {@linkplain Class class} of the managed bean or session bean or * of the bean that declares the producer method or field. * * @return the bean {@linkplain Class class} */ public Class<?> getBeanClass();
This means that for your 'mybean' producer it will not return UserInfo as you are expecting, but ProducesUtil instead.
-
6. Re: How to get Produces bean instance in weld-1.0.2-snapshot
alin.heyoulin.qq.com Jul 22, 2010 3:23 AM (in response to alin.heyoulin.qq.com)Ok. But how can i get producer bean from bean name? I can do it using weld 1.0.1.
-
7. Re: How to get Produces bean instance in weld-1.0.2-snapshot
pmuir Jul 27, 2010 7:46 AM (in response to alin.heyoulin.qq.com)
he youlin wrote on Jul 21, 2010 09:47:public class ProducesUtil { @Produces @SessionScoped @Named("myBean") UserInfo getUserInfo() { SpringUser springUser\=(SpringUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); return new UserInfo(springUser.getUsername(),springUser.getName(),springUser.getPassword(),springUser.getRoles(),springUser.getRights()); } }
Ok, I'm pretty sure this is a bug in Weld. Can you report a JIRA issue, ideally with an Arquillian test case, or at least the bean class you want us to test, with no external dependencies.