cdi

@Injection is not working for CDI bean

旧巷老猫 提交于 2020-01-13 17:05:43
问题 I have a CDI bean where I'm using @ConversationScoped. When I try to do an @Inject for the Conversation object, I get a NPE. @ConversationScoped @Named("customerbean") public class CustomerBean implements Serializable { @Inject private Conversation conversation; private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("ba"); private EntityManager em; private Customer customer; boolean disabled; public CustomerBean() { beginConversation(); customer = new Customer(

CDI - ApplicationScoped but configured

空扰寡人 提交于 2020-01-13 07:20:33
问题 Problem Using CDI I want to produce @ApplicationScoped beans. Additionally I want to provide a configuration annotation to the injection points, e.g.: @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Configuration { String value(); } I do not want to write a separate producer for each different possibility of value . Approach The usual way would be to make a producer and handle the injection point annotations:

CDI - ApplicationScoped but configured

安稳与你 提交于 2020-01-13 07:20:13
问题 Problem Using CDI I want to produce @ApplicationScoped beans. Additionally I want to provide a configuration annotation to the injection points, e.g.: @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Configuration { String value(); } I do not want to write a separate producer for each different possibility of value . Approach The usual way would be to make a producer and handle the injection point annotations:

Container testing of jar with embedded glassfish using gradle fails

烈酒焚心 提交于 2020-01-13 05:08:05
问题 I am using JUnit and embedded glassfish to test some code using CDI. This seems fairly straightforward but I must be missing something. I've created a simple project which demonstrates the problem. https://github.com/dantwinkler/container-test-embedded-glassfish This is the stack trace if no parameters are set. If the domain.xml is specified in the embedded container properties the tests still fail but because it says the test can not be found. The next step is to try to get things working

Calling a CDI session scoped producer method from an EJB stateless session bean

本小妞迷上赌 提交于 2020-01-12 18:22:51
问题 I want to inject the current user using @Inject @Current User across all layers (i.e. web layer, EJB layer). In order to do this, I have the following CDI Producer method: @Named @SessionScoped public class UserController { @Resource SessionContext sessionContext; @EJB UserDao userDao; @Produces @Current public User getCurrentUser() { String username = sessionContext.getCallerPrincipal().getName(); User user = userDao.findByUsername(username); } } @Qualifier @Target({TYPE, METHOD, PARAMETER,

Calling a CDI session scoped producer method from an EJB stateless session bean

北战南征 提交于 2020-01-12 18:19:17
问题 I want to inject the current user using @Inject @Current User across all layers (i.e. web layer, EJB layer). In order to do this, I have the following CDI Producer method: @Named @SessionScoped public class UserController { @Resource SessionContext sessionContext; @EJB UserDao userDao; @Produces @Current public User getCurrentUser() { String username = sessionContext.getCallerPrincipal().getName(); User user = userDao.findByUsername(username); } } @Qualifier @Target({TYPE, METHOD, PARAMETER,

CDI Ambiguous dependencies

扶醉桌前 提交于 2020-01-12 13:52:33
问题 I have a @SessionScoped @Named bean with a @Producer method for a user object: @Named @SessionScoped public class UserBean implements Serializable { //... @Named @Produces @LoggedIn @SessionScoped public MyUser getCurrentUser() {return user;} } This works fine in my setup (JBoss-7.1.1-Final) and it's no problem to access the user fields from JSF pages with #{currentUser.name} . The qualifier is org.jboss.seam.security.annotations.LoggedIn . Now I want to @Inject this user in a field in

JBoss Weld + java.lang.OutOfMemoryError: PermGen space

亡梦爱人 提交于 2020-01-12 13:46:28
问题 I've just switched to Weld to make use of CDI JSF 2 Beans + conversation scope. Here's my maven dependency : <dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet</artifactId> <version>1.0.1-Final</version> <type>jar</type> <scope>compile</scope> </dependency> Here's the entry in my web.xml : <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> One thing i noticed immediately is i just need to reload my tomcat 7 for like

JBoss Weld + java.lang.OutOfMemoryError: PermGen space

雨燕双飞 提交于 2020-01-12 13:44:05
问题 I've just switched to Weld to make use of CDI JSF 2 Beans + conversation scope. Here's my maven dependency : <dependency> <groupId>org.jboss.weld.servlet</groupId> <artifactId>weld-servlet</artifactId> <version>1.0.1-Final</version> <type>jar</type> <scope>compile</scope> </dependency> Here's the entry in my web.xml : <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> One thing i noticed immediately is i just need to reload my tomcat 7 for like

Is it possible to observe a CDI Event inside a WAR when packaged as EAR

为君一笑 提交于 2020-01-12 07:47:10
问题 I have an Enterprise Application Archive ( EAR ) containing multiple backend modules ( EJB ) as well as some web modules ( WAR ). The Event gets fired inside one of the backend modules: @Inject private Event<MyEvent> myEvent; ... public void fireEvent() { myEvent.fire(new MyEvent()); } ... It can be observed in any of the other backend modules with code like this: public void listener(@Observes MyEvent myEvent) { .. } But I can't retrieve the event inside the WARs. Is this because of