cdi

how to instantiate more then one CDI/Weld bean for one class?

陌路散爱 提交于 2019-12-19 06:46:08
问题 In Spring it was possible to instantiate any class by defining the corresponding bean in xml conf. It was also possible to instantiate more then one bean for the same class with different parameters..... Are the such features in CDI as well, namely is it possible to create different instances of the same class with different initialization parameters? Is it also possible to create a bean without changing the class....I mean without adding annotation? ADDED Let me make an example. <bean id=

CDI deployment failure:WELD-001414 Bean name is ambiguous

我只是一个虾纸丫 提交于 2019-12-19 06:22:13
问题 I have an application, which has multiple modules and various dependencies. When I deploy the application on Glassfish 4, I am getting error: org.jboss.weld.exceptions.DeploymentException: WELD-001414 Bean name is ambiguous. Name JerseyClassAnalyzer resolves to beans: [Managed Bean [class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] with qualifiers [@Default @Named @Any], Managed Bean [class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] with qualifiers [@Default

CDI deployment failure:WELD-001414 Bean name is ambiguous

时光总嘲笑我的痴心妄想 提交于 2019-12-19 06:21:44
问题 I have an application, which has multiple modules and various dependencies. When I deploy the application on Glassfish 4, I am getting error: org.jboss.weld.exceptions.DeploymentException: WELD-001414 Bean name is ambiguous. Name JerseyClassAnalyzer resolves to beans: [Managed Bean [class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] with qualifiers [@Default @Named @Any], Managed Bean [class org.glassfish.jersey.internal.inject.JerseyClassAnalyzer] with qualifiers [@Default

Java EE 7 CDI Manual Instantiation

痴心易碎 提交于 2019-12-19 03:45:56
问题 I have a Class with fields annotated with @Inject. I instantiate the Class using reflection, but I want the CDI to inject instances to do the Class instance fields. Is there a way of doing it? Object myInstanceWithDependecies = Class.forName(“com.package.MyClass").newInstance(); CDI.injectAll(myInstanceWithDependecies);//This is what i want Does someone know how to do this? I would appreciate if there was a way of doing it without scanning each field using reflection. Thanks in advance. 回答1:

When should you explicity name a Managed Bean?

为君一笑 提交于 2019-12-19 03:41:38
问题 With all the research I've done on creating managed beans, what I've not noticed (or what I may have overlooked) is when to use explicit naming of the bean e.g. @Named(name = "someBean") . I guess what it hard for me to understand is why you would want to name the bean anything other than your class name: @Named(name = "someBean") public class SomeBean implements Serializebale { } With all the examples I've seen, some use the the explicit name and some just use @Named to leave the default

What is the equivalent of @ManagedBean(eager=true) in CDI

怎甘沉沦 提交于 2019-12-19 00:45:51
问题 As we all know that it is recommended to use annotations from javax.enterprise.context instead of javax.faces.bean as they are getting deprecated. And we all found ManagedBeans with eager="true" annotated with @ApplicationScoped from javax.faces.bean and having a @PostConstruct method are very useful to do web application initialization e.g: read properties from file system, initialize database connections, etc... Example : import javax.faces.bean.ApplicationScoped; import javax.faces.bean

CDI : WELD-001408 Unsatisfied dependencies, how to resolve it?

一个人想着一个人 提交于 2019-12-18 18:48:09
问题 I do a small test project with CDI. My application is composed of an EJB EAR and WAR, all deployed on Glassfish 4. I'm using Hibernate 4.3.4 to access the database. My goal is to verify that a class in an EJB (DAO) can receive an injection of an EntityManager. The pattern SessionBean + EJB is not fantastic but I have to modify an application already created so I do not have much choice. Here is my code of the EJB: @Named public class DAOTest implements Serializable { private static final long

Can CDI managed beans and JSF managed beans talk to each other?

烂漫一生 提交于 2019-12-18 16:57:41
问题 I have a Tomcat 6 JSF web application that I'd like to set up with CDI beans. I will have to convert the project to CDI gradually though. My question is: can CDI beans and traditional JSF managed beans be injected into each other? Thanks. 回答1: All JSF managed beans (JMB) either are CDI managed beans (CMB) automatically, or can be recognized as such using the beans.xml marker file. (The requirements of a CMB are set very low and basically just dictate the existence of a non-parameter

PreRenderView incrementally called on every postback

我与影子孤独终老i 提交于 2019-12-18 13:26:50
问题 I have an issue with the order and number of executions of an f:event type="preRenderView" . During my search here I found as usual answers from BalusC in this and this post related to my problem - still it leaves two questions for me: When I put one f:event type="preRenderView" in the template file (for managing common tasks like checks about the user state which applies for all my views) and another f:event type="preRenderView" in each view (for handling view specific initializations), I

How to inject EntityManager in CDI (weld)?

南笙酒味 提交于 2019-12-18 13:08:21
问题 In my project , I use JSF+JPA+CDI+WildFly 8.2 in the persistence layer. I have a BasicDao , like this: public class BasicDao<M, K> { private org.jboss.logging.Logger logger = org.jboss.logging.Logger .getLogger("BasicDao"); @Inject @Primary protected EntityManager em; Class<M> mclass; public EntityManager getEm() { return em; } public void setEm(EntityManager em) { this.em = em; } @Transactional(value=TxType.NOT_SUPPORTED) public M find(K id){ return em.find(mclass, id); } @Transactional