cdi

Injection of @PersistenceContext in CDI-Unit

a 夏天 提交于 2019-12-09 06:57:33
问题 Here is the unit testing code. When we run unit test code (SampleServiceTest2); EntityManager injected in AbstractDao is always null! How can we inject em during unit test. *** SampleServiceTest2.java import javax.inject.Inject; import org.jglue.cdiunit.CdiRunner; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(CdiRunner.class) public class SampleServiceTest2 { @Inject SampleService greeter; @Test public void testGreeter() throws Exception { System.out.println("before2");

CDI with unmanaged objects

荒凉一梦 提交于 2019-12-09 05:57:55
问题 Suppose that I have two classes, first a class without any properties, fields or annotations: public class B {} And a class which gets B injected, like this: public class A { @Inject private B b; public B getB() { return b; } } Now class A is pretty useless until we use it, so there are two options: @Inject it Construct it manually, using the trusty "new A()" If A gets injected, CDI manages it and is kind enough to inject B which has the implicit scope of @Dependent. Cool, just what I want.

Weld not initializing properly

旧时模样 提交于 2019-12-09 03:06:43
问题 I am setting up basic environment for learning CDI in JavaEE7. I have the following code for starting Weld . Just a startup and shutdown. package com.anshbansal; import org.jboss.weld.environment.se.Weld; import org.jboss.weld.environment.se.WeldContainer; public class Main { public static void main(String[] args) { Weld weld = new Weld(); WeldContainer container = weld.initialize(); weld.shutdown(); } } I am getting following on my console. SLF4J: Class path contains multiple SLF4J bindings.

Getting a GET request param into an @ViewScoped bean

好久不见. 提交于 2019-12-09 01:08:39
问题 I have a (request-scoped) list from which the user may select a "PQ" (list of links). When clicked or otherwise entered into the browser the main page for each PQ shall be displayed. Each PQ's page is of the form http://localhost:8080/projectname/main.jsf?id=2 Here's the PQ bean first: @Named @ViewScoped public class PqHome implements Serializable { @PersistenceContext(unitName="...") private EntityManager em; private Integer id; private PQ instance; @PostConstruct public void init() { System

JSF 2.2 and Spring 4 and CDI on different layers without losing Spring features

孤人 提交于 2019-12-08 20:10:40
I’m a little confused after all articles that I read. I don’t want to use additional services as I’ll need if I use Weld Framework instead of simple Spring qualifier in service layer. And I have one service which uses JavaMailSender. I just want to have ability use AOP in controller layer with JSF. I got absolutely confused after reading about support JSR-229 and JSR-330 by Spring (even Spring 3) Spring 3 And JSR-330 @Inject And @Named Example Does it mean that I can do smth like that and don't lose posibility use Spring features like AOP ? (Yes, I think.) import javax.inject.Inject; import

Why CDI beans don't support final methods

懵懂的女人 提交于 2019-12-08 19:27:02
问题 I just incurred in the infamous JavaEE CDI error under GlassFish server: org.glassfish.deployment.common.DeploymentException: CDI deployment failure:Exception List with 2 exceptions: Exception 0 : org.jboss.weld.exceptions.DeploymentException: WELD-001437 Normal scoped bean class ASController is not proxyable because the type is final or it contains a final method public final void ASController.selectPath(org.primefaces.event.NodeSelectEvent) - Managed Bean [class ASController] with

What is CrashLoopBackOff status for openshift pods?

被刻印的时光 ゝ 提交于 2019-12-08 18:48:33
问题 There is more than one example where I have seen this status from a pod running in openshift origin. In this case it was the quickstart for the cdi camel example. I was able to successfully build and run it locally (non - openshift) but when I try to deploy on my local openshift (using mvn -Pf8-local-deploy ), I get this output for that particular example (snipped for relevance) :- [vagrant@vagrant camel]$ oc get pods NAME READY STATUS RESTARTS AGE cdi-camel-z4czs 0/1 CrashLoopBackOff 4 2m

How to write main() using CDI in Java EE?

强颜欢笑 提交于 2019-12-08 18:21:25
I have a no-client application that I wish to run. It will have no clients but it will make HTTP calls and act as client for other services. It would run for perhaps a few hours or days (but it will not require periodic runs -- just one-shot). I want to run it in a Java EE 7 container, because of the benefits of standard Context Dependency Injection (CD), and a standard JAX-RS client (new since Java EE 7). It is also nice to have services such as JMS, JPA. The question is how do I write / annotate the main method in a standard way? @Inject on a method is no good because such methods must

UnserializableDependencyException: WELD-001413: The bean declares a passivating scope but has a non-passivation-capable dependency

对着背影说爱祢 提交于 2019-12-08 17:11:59
问题 I have the below CDI managed bean: @Named @SessionScoped public class InfoPageController implements Serializable { @Inject private InfoPageMapper mapper; } It throws the below exception during deployment to GlassFish 4.1: Exception while loading the app : CDI deployment failure:WELD-001413: The bean Managed Bean [class de.triaconsulting.cashyourgame.fe.controller.InfoPageController] with qualifiers [@Default @Any @Named] declares a passivating scope but has a non-passivation-capable

Startup ejb bean does not work

只谈情不闲聊 提交于 2019-12-08 17:00:06
问题 I am trying to do something at startup using a startup ejb. But my bean is never called. This is my bean: import javax.annotation.PostConstruct; import javax.ejb.Startup; import javax.inject.Singleton; @Singleton @Startup public class StartupBean { @PostConstruct public void doSomething(){ System.out.println("why??"); } } I am using jboss 7.1.1. What am i doing wrong? You can find my source code at bitbucket: https://bitbucket.org/cremersstijn/jee/src/9e22ed2b798a/simple-startup-bean 回答1: You