cdi

Issue with EJB 3.1 injected with CDI bean while running JUnit

大憨熊 提交于 2019-12-22 10:18:47
问题 I created a EJB3.1 and injected CDI bean using the @inject but facing some issues while unit testing however when tested from the servlet its working fine. I have the beans.xml in the WEB-INF folder. Below is my EJB code: @Stateless public class CdiUsingEjb { @Inject private HelloServletCDIPojo helloServletCDIPojo; public String greet() { assert helloServletCDIPojo != null; return helloServletCDIPojo.from(); } } Below is my CDI bean: public class HelloServletCDIPojo { public String from() {

JavaEE CDI in Weld: Generic Events?

狂风中的少年 提交于 2019-12-22 10:02:52
问题 I have an idea for a specific event handling based on generics, but seems like Weld can't handle them. I asked google but couldn't find an alternative CDI extension for this. Question : is there a CDI extension, that can handle event propagation of generic-typed events? In the following the explicit problem I have. I have three general events, EntityCreated, EntityChanged and EntityDeleted. The base class for them is defined like this: public abstract class DatabaseEvent<TargetType> { public

Controlling CDI Startup inside EJB 3.1

試著忘記壹切 提交于 2019-12-22 07:24:49
问题 I'm new in here and also new to the CDI world, and the first task I got in my job was to find out a way to controlled CDI uploading. We are using both EJB 3.1 and CDI 1.0 , and because they are controlled by different containers, we can control when and in what order the EJB Managed Beans will be up by using @Startup and @Singleton annotations. But the @Inject CDI bean I have declared in my class is coming as null since the CDI Container hasn't started yet. I have been trying for several days

Transaction management and CDI

让人想犯罪 __ 提交于 2019-12-22 07:02:00
问题 I would like to develop an application with CDI (I use Spring usually) to discover this technology. I have read many articles about CDI to learn how it works. I have a simple question about transaction management (for persistence in database for example): Is it mandatory to use EJB 3.1 to have transaction management or is it possible to have it with CDI only ? Thanks. 回答1: No, you can do it with CDI. You simply need to create an interceptor that starts, commits or rollsback a transaction. It

CDI Producer and Injection

十年热恋 提交于 2019-12-22 07:01:20
问题 i want to use a producer in my application but i'm stuck at the point, where i'm trying to inject the bean. im getting the famous WELD-001409 error. please lighten up my understanding of cdi producer. here's my interface: @Named public interface MessageSender { void sendMessage(); } the bean: public class EmailMessageSender implements MessageSender { @Override public void sendMessage() { System.out.println("Sending email message"); } } and the producer: @SessionScoped public class

How does @SessionScoped work with EJB? Is CDI only for web-tier?

拜拜、爱过 提交于 2019-12-22 04:07:37
问题 How is the session defined in @SessionScoped CDI bean? Is this annotation valid only when called from Servlet container, where the session is well defined in form of HttpSession ? If not, than how an EJB with @Inject @SessionScoped MyBean myBean can know what the session really is ? I mean, methods of this EJB could have been invoked by a standalone client, RESTful WS or by some other view. What should happen in such case? Should the annotation have no meaning, should it inject fresh MyBean

CDI. How to check whether bean instantiated or not?

我是研究僧i 提交于 2019-12-22 01:19:16
问题 I've got a name of CDI @Named bean. For example, 'firedEmployeeBean'. Is there any way in other CDI bean check whether 'firedEmployeeBean' already instantiated or not? 回答1: As already stated if you use @Inject once you check it will be. What you instead want is to have a property to tell you what you want: boolean initiated; if this simple solution does not cut it I would recommend to use Deltaspike: MyBean myBean = BeanProvider.getContextualReference(MyBean.class, true); Note the second

Non-lazy instantiation of CDI SessionScoped beans

↘锁芯ラ 提交于 2019-12-21 23:01:06
问题 CDI newbie question. Simple test scenario: JSF + CDI SessionScoped beans. I need an elegant way to instantiate a known set of session scoped CDI beans without mentioning them on a JSF page or calling their methods from other beans. As a test case - a simple logging bean, which simply logs start and end time of an http session. Sure, I could create an empty JSF component, place it inside of a site-wide template and make it trigger dummy methods of the required session beans, but it's kinda

Weld using alternative producer from src/test/META-INF/beans.xml

≯℡__Kan透↙ 提交于 2019-12-21 21:34:24
问题 I am trying to use Weld SE 2.3.0.Final to swap an alternative implementation of an injected dependency during testing by supplying a different beans.xml in src/test/resources/META-INF It always seems to use the main version of beans.xml though and I'm not sure why. First of all here are the supporting classes Engine.java public interface Engine { void start(); void stop(); } DefaultEngine.java @Vetoed public class DefaultEngine implements Engine { public void start() { System.out.println(

What scope do JAX-RS 2 filters have?

♀尐吖头ヾ 提交于 2019-12-21 21:32:44
问题 I am using RestEasy 3.0.2 which is one of the first JAX-RS 2 implementations and run my application within a Tomcat 7. I also make use of injection in my application via WELD which is integrated with RestEasy via its CDI adaptor. Everything works fine so far. Now, I wrote an implementation of a ContainerRequestFilter to perform authentication of incoming requests before they hit a resource. The JAX-RS standard says that injection is possible for every resource and every other JAX-RS component