FAQ Database Discussion Community


Returning CDI bean reference in EJB call

java-ee,cdi
Is the following allowed in Java EE? I have a @Singleton session bean that works as a registry and automatically discovers certain strategies that are used throughout the application, like this: public interface Strategy { Class<?> supportedType(); } @Singleton public class StrategyRegistry { @Inject private Instance<Strategy> strategies; private Map<Class<?>, Strategy>...

Frameworks and specification for JPA, CDI and JSF

spring,hibernate,jsf,jpa,cdi
I have read and I have understood that JPA, JSF, CDI are only specifications. Such as: JPA - [Hibernate, Toplink], JSR-000338 CDI - [Spring - Google Guice, PicoContainer], JSR299 JSF - [Primefaces, IceFaces, RichFaces], JSR-000314 So, if they are only specification in a paper, why the packages says, "javax.persistence...", “javax.faces."?...

PAX-CDI change log level

osgi,cdi,pax
I am using pax-cdi and when I start it I get hundreds lines of information - what package is scanned, qualifiers etc. How to disable outputting this information?

Inject CDI bean into JSF @ViewScoped bean

jsf,jsf-2,cdi,view-scope
I have a problem with JSF, CDI project. I did a lot of research and I found that in CDI there is no @ViewedScoped annotation. I solving problem with ajax based page with dialog. I want to pass variable to dialog from datatable. For this purpose, I can't use @RequestedScoped...

Spring-boot+JPA EntityManager inject fails

spring,java-ee,jpa,spring-boot,cdi
In my J2EE application I try to use spring-boot and JPA technologies with injection of EntityManager into DAO layer. However, I have some problems... My repository for user CRUD: @Repository public class UserRepositoryImpl implements UserRepository { @PersistenceContext(unitName = "data") private EntityManager entityManager; // and crud methods } My spring-boot application...

CDI will not work with implicit @Dependent scope, unsatisfied injection point compile time error

dependency-injection,glassfish,cdi,managed-bean,glassfish-4.1
The container is Glassfish 4.1 I am having a very weird issue with CDI right now. If I don't annotate my NumberGenerator services @Dependent, then I keep getting unsatisfied injection point error when I run the app. But if I explicitly annotate my NumberGenerator implementations, then everything will work. In...

@ManagedProperty with request parameter not set in a @Named bean

jsf,cdi,managed-bean,http-request-parameters,managed-property
I've a CDI managed bean wherein I'd like to set request parameters as managed properties: import javax.inject.Named; import javax.enterprise.context.RequestScoped; @Named @RequestScoped public class ActivationBean implements Serializable { @ManagedProperty(value="#{param.key}") private String key; @ManagedProperty(value="#{param.id}") private Long id; // Getters+setters The URL is domain/activate.jsf?key=98664defdb2a4f46a527043c451c3fcd&id=5, however the properties are never set and remain null....

Specifying different subclass implementations in CDI

java,cdi,weld
I have two classes, A and B, which need to use a service. There are two services, S1 and S2. S2 extends S1. I wish to inject S1 into class A and S2 into class B. How can I accomplish this in CDI? public class S1 {} public class S2...

Handle circular dependency in CDI

java,dependency-injection,cdi
I have situation like this. I cannot see any errors but I am not getting my results. @ApplicationScoped public class A { private B b; @Inject public A(B b) { this.b = b; } } @Singleton public class B { private A a; @Inject public B(A a) { this.a =...

Inject Stateless (Webservice)Bean into another Bean

java,web-services,java-ee,jboss,cdi
I try to make a little test with versioning a soap service. My idea was that the business logic always implement the newest version and a soap service provide its functionality. To support the older version of the interface I want to map the jaxb classes via mapping framework to...

CDI+OSGI: bundle packages scope

java,osgi,cdi,weld,pax
I use javase and solution osgi (felix)+cdi(weld)+paxcdi. I have two bundles A and B. Bundle B is a lib bundle. In bundle A I have one class and one package. package com.example.firstpackage; import com.example.secondpackage.Class2; public class Class1{ @Inject private Class2 class2; } In bundle B I have two classes and...

Inject @ViewScope cdi bean into JAX-RS resource

jsf,jsf-2,jax-rs,cdi,omnifaces
I'm using MyFaces Apache 2.0.3 JSF, WAS 8.0.0.10 Currently I'm trying to inject an @ViewScope cdi bean, @ViewScope in JSF 2.0 provided by OmniFaces's library. But I get an error: WebBeans context with scope type annotation @ViewScoped does not exist within current thread. When I try to inject an @SessionScope...

Performance: Utility class vs. CDI bean

java,performance,cdi,weld
I want to externalize commonly used applicationlogic into a "utility class" called Helper. The applicationlogic needs other CDI beans to work. Two possibilities: a) @SessionScoped class ControllerWithCdiBean { @Inject Helper helper; public void doIt() { Object result = helpder.calculate(); } } @RequestScoped class Helper{ @Inject Service anyService; public Object calculate()...

Get new instance of session scoped bean with other name

jsf,cdi,jsf-2.2
I have a session scoped bean for a UI to edit some data. It is annotated with @Named and @SessionScoped and all runs in JBoss 6.2. Now I got the requirement for a nearly similar edit UI. The problem is that the two UIs can exist in parallel. So for...

What is difference between resource injection and dependency injection (CDI) in Java?

java,dependency-injection,cdi
I have been learning Java EE for while and found Java EE provides two types of injection mechanisms Resource Injection Dependency Injection Please guide me to understand the difference between Resource Injection & Dependency Injection....

EJB Interceptors and transaction lifecycle OR how to intercept a commit/failure event?

java,java-ee,ejb,cdi
I have an EJB interceptor and I follow the BCE pattern suggested by Adam Bien, that is, all EJB calls on the boundary starts and finish a transaction which means there is no nested EJB calls (there might be nested CDI injected Bean calls though, but those should be inside...

Use alternative producers of EntityManager / EMF in integration tests

java,maven,jpa,integration-testing,cdi
I looking for way how to use CDI and alternative producers in integration tests. When i speak about producers, i mean EMF producer. Reason for different EMF producer is that i want to use testing in-memory database (different persistence unit). Is there easy way how to start CDI for integrations...

Getting WELD-001303 error when implementing custom CDI extension for @SessionScoped scope

java-ee,cdi,java-ee-7,named-scope,java-ee-web-profile
I'm trying to implement a custom CDI scope and I thought it's the easiest to start by extending the existing @SessionScoped. I started by following this tutorial. However, when visiting an XHTML page which references a CDI bean with my scope, this leads to org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for...

@Inject field is always null

java,cdi
I try to @Inject a field (its a jar module, empty beans.xml is existing under META-INF) like this: IDataProvider Interface public interface IDataProvider { void test(); } DataProvider implementation import javax.enterprise.context.ApplicationScoped; @ApplicationScoped public class DataProvider implements IDataProvider { private int i; public DataProvider() { i = 42; } @Override public...

CDI Qualifier Inheritcance

java,nested,cdi,inherited
Is there a way I can do something like that in CDI: @Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Qualifier public @interface ServerConfiguration { @Nonbinding String url() default "http://localhost:8080"; @Nonbinding String username() default ""; @Nonbinding String password() default ""; } And then define a second annotation similar to that: @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @ServerConfiguration(username...

WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default

jsf,cdi,managed-bean
I'm a Java EE-newbie. I want to test JSF and therefore made a simple program but can not deploy it. I get the following error message: cannot Deploy onlineshop-war deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with...

The annotation “@Added” is disallowed for this location, when using custom annotation with events in CDI

java,events,cdi
When using a custom qualifier near the @Observes qualifier to catch an event I have this compilation error. All the classes are in the same package so the problem is not the import statements. I already checked that. @Inject private Logger logger; List<Book> inventory = new ArrayList<>(); public void addBook(@Observes...

Initialize subclasses after @PostConstruct

java-ee,cdi
I'm using the Context Dependency Injection CDI 1.1 framework from JavaEE 7, within the WildFly 8.2 application server I want to initialize subclasses after a @PostConstruct of the super class So I do somthing like that // case 1: it's working but it's not simple to understand public class A...

JSF Interceptor doesn't fire

cdi,jsf-2.2,interceptor
Why my interceptor doesn't work? MyLog.java @Inherited @InterceptorBinding @Retention(RUNTIME) @Target({METHOD, TYPE}) public @interface MyLog { } MyLogger.java @Interceptor @MyLog @Priority(Interceptor.Priority.APPLICATION) public class MyLogger { @AroundInvoke public Object log(InvocationContext context) throws Exception{ System.out.println("begin " + context.getMethod().getName()); Object obj = context.proceed(); System.out.println("end " + context.getMethod().getName()); return obj; } } PerguntaController.java import interceptor.MyLog;...

@Schedule with CDI error:Could not get current FacesContext

java,ejb,scheduled-tasks,cdi
I'm trying to make a scheduler with the use of CDI My EJB Scheduler import java.time.LocalDateTime; import javax.ejb.Schedule; import javax.ejb.Singleton; import javax.inject.Inject; import javax.security.auth.login.LoginException; import br.com.timbrasil.bluemonster.csr.Crawler; @Singleton //@Startup public class Scheduler { @Inject private Crawler crawler; //TODO https://java.net/jira/browse/EJB_SPEC-1 @Schedule(hour="*",minute="*/1",second="0") public void downloadCsr() { System.out.println("Iniciando download dos CSRS"); LocalDateTime...

How to @Inject values from a .properties file with CDI

properties,dependency-injection,cdi
How can i inject some values from a properties file? I have a .properties file with some keys and values, i would like to inject those to use on some classes, something like: @Inject(file = "/WEB-INF/abc.properties",key ="path") private String path; So when i use the path it has the value...

@PostConstruct not invoked in PhaseListener

jsf-2,cdi,postconstruct,phaselistener
I am using jsf2.2 with wildfly 8.1 and javaee7. My CDI bean injection in the phaselistener works as expected, but the @PostConstuct method is never invocked I have tried to annotate the phaselistener with @javax.enterprise.context.ApplicationScope, SessionScope and Dependent to no avail. Apart from naming, this is the exact thing i...

EJB Ambiguous dependencies: How to specify which class to Inject

java,java-ee,dependency-injection,ejb,cdi
I am trying to inject an object in my EJB like this: @Stateless @Path("/auth") public class Login { @Inject UsernamePasswordCredentials credentials; The problem is the UsernamePasswordCredentials has a child class and both classes have the same qualifiers which causes an ambiguous dependencies. How do I specify that I want to...

DeploymentException: WELD-001408 on injection when using extended classes

java-ee,dependency-injection,cdi,jboss-weld
I have the following DBOs: public abstract class DetailDbo{ .... } public abstract class MasterDbo<T>{ .... } public class B extends DetailDbo{ .... } public class A extends MasterDbo<B>{ .... } My service: @Stateless @LocalBean public class MyService<T extends MasterDbo<D>, D extends DetailDbo>{ //implemetation } My bean: public class MyBean<T...

Dao, Service layer in legacy code [closed]

java,spring,ejb,cdi
This Question is about design in business layer. What is the best way to instantiate Dao or Service class in legacy code. new in every class where Dao or Service is needed is imho bad approach. They should be stateless, singletons. For sure I am not able to use Spring,...

WELD-001201: Error loading beans.xml + Tomcat 7.0.59

java,tomcat,tomcat7,cdi,weld
I have one application using CDI with weld 2.2.9.Final and embedded Tomcat 7.0.57 and everything works fine. After upgrading to embedded Tomcat 7.0.59, when I'm starting my application I got the following exception: Caused by: org.jboss.weld.exceptions.IllegalStateException: WELD-001201: Error loading beans.xml jndi:/localhost/WEB-INF/beans.xml at org.jboss.weld.xml.BeansXmlParser.parse(BeansXmlParser.java:124) at org.jboss.weld.bootstrap.WeldBootstrap.parse(WeldBootstrap.java:131) at...

CDI session scoped bean not destroyed results in memory leakage

jsf,cdi,destroy,weld,session-scope
I have a question regarding the lifecycle of session scoped CDI beans. As far as I understand, a session scoped CDI bean is constructed by the container when the session starts and destroyed when the session ends. Before the bean is destroyed the @PreDestroy Method is invoked as described here...

I cannot instantiate my bean using @Inject and Vaadin CDI

java-ee,vaadin,cdi,vaadin7
I am trying to inject my components and beans using Vaadin-cdi. Note the code below is simplified a bit. @Theme("valo") @CDIUI("") public class MyUI extends UI { @Inject private CDIViewProvider provider; @Override protected void init(VaadinRequest request) { Navigator navigator = new Navigator(); navigator.addProvider(provider); navigator.navigateTo("mypanel"); } } And here goes MyPanel:...

IBM WAS 8.5.5.4 : A POJO with interface and implementation in different JARs cannot be injected successfully inside an EJB 3.1 bean in another EJB jar

java-ee,websphere,cdi,ejb-3.1,websphere-8
I'm developing a Java EE 6 application that must work in both JBoss WildFly 8.2.0 and IBM WAS 8.5.5.4 with the same EAR package. The application structure is pretty simple. It basically follows the below one: EAR |__ /lib/ |____|__ API.jar |____|__ IMPL.jar | |__ EJB.jar |__ WebConsole.war |____|__/lib |_______|__C.jar...

If we inject a SessionScoped bean into a Stateless bean, what happens if there is no HTTP session?

java,java-ee,architecture,ejb,cdi
Our application consists of web pages that interact with backing beans and Stateless EJB services, but there is also a remote client that interacts with the Stateless EJB services. Many of the services query the DB and then filter the result set based on the current user/caller (for example, users...

Arquillian: Attempted to register the same Observer, ServerSetupObserver multiple times

junit,ejb,cdi,wildfly-8,jboss-arquillian
I am trying to configure arquillian with wildfly but am the following Getting error in the process of running test: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:165)....... Caused by: java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ........... Caused by: java.lang.RuntimeException: Could not create new instance...

Dynamic Web Project - Project Facets not displaying CDI as a project facet

java,eclipse,java-ee,cdi,linuxmint
I'm trying to add CD,I as a project facet to a Dynamic web project. But when clicking on the project facets view there is no CDI option in the Project Facet list as you can see: I tried following this suggestion in where they said to erase possible conflicting jres,...

How add FacesMessage to CDI security interceptor?

java,cdi
I've created my Security Check by this couple examples: Stackoverflow Blog By Adam Warski But unfortunatly I can't see how to add FacesMesagges exception in case the check fails. My files: CheckAction @Inherited @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) public @interface CheckAction { @Nonbinding public ESysObject object() default ESysObject.NONE; @Nonbinding...

CDI Bean member loses value during request

jsf-2,primefaces,cdi
I have years of experience developing JSF applications, but this is a confusing bug, which is driving me insane. I think I need a fresh pair of eyes to find the possible error. First off, the details about the environment: JDK: 8u40 Server: WildFly 8.2.0.Final Libs: CDI 1.2, JSF 2.2,...

CDI @Instance to collect @Any, but access the Qualifiers (esp. @Named)

java,java-ee,cdi
I want to collect all beans that are produced somewhere. Something like this: static class Greeting { public final String text; public Greeting(String text) { this.text = text; } } @Produces @Named("hi") Greeting hi = new Greeting("Hi"); @Produces @Named("hello") Greeting hello = new Greeting("Hello"); @Inject Instance<Greeting> greetings; @Test public void...

What is the difference between Stateless Session Beans and Request Scoped beans

jsf,java-ee,scope,ejb,cdi
I know that Stateless Session Beans refers to EJB beans while Request Scoped refer to CDI beans (or JSF managed beans), so I will start by giving their both definitions from the Java EE Tutoriel. Stateless Session Beans definition: A stateless session bean does not maintain a conversational state with...

How to inject a http session attribute to a bean using CDI

jsf,session,cdi,managed-bean
I have some legacy code that put objects as http session attributes using code like this: MyObject object = new MyObject(); Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap(); sessionMap.put("attrname", object); The old facelets accessed the code using @ManagedProperty("#{attrname}") private MyObject object; Is there any way using CDI (@Inject) to inject this session...

Use JSF, JPA, JTA, JAAS, CDI, Bean Validation with Tomcat? [closed]

jsf,tomcat,jpa,cdi,jta
Is it possible to use the following APIs with tomcat (as a lightweight server): JSF, JPA, JTA, JAAS, CDI, Bean Validation. ...

Intercept Exceptions for logging with CDI's AOP on Java EE 7

exception,logging,cdi,aop,java-ee-7
I have the following class snippet, from which I'd like to remove the repetitive logging code and move it to an Interceptor using CDI's AOP. /** * Javadoc omitted */ public abstract class JpaDao<T extends LongIdentifiable> implements GenericDao<T> { @Override @Transactional public Long persist(T type) throws GeneralPersistenceException { if (type...

Wildfly 8.2 + JSF + SessionScoped : sometimes wrong data returned

jsf,session,cdi,wildfly,jboss-weld
In one of our systems in production we encounter a very weird problem in jboss 8.2 and latest JDK 7, centos 7 64 bits, latest primefaces on javax.enterprise.context.SessionScoped beans. (No jsf annotations are used in the whole project, only CDI annotation to avoid potential conflicts) At some point in time...

Cant inject Gson in java with @inject

cdi,inject,producer
Hello i have the following problem, when i load the class without the @inject private Gson gson it runs normaly, but when i put it it throws a exception. Class that calls gson. package core.control; import java.util.List; import javax.inject.Inject; import javax.inject.Named; import com.google.gson.Gson; import core.dao.SistemaDao; import core.model.Sistema; @Named public class...

CDI: Obtaining InjectionPoint when producing a scoped bean

java,cdi
whats the easiest way to obtain the InjectionPoint when your producer method is producing a scoped bean? For some reason the spec does only allow injection of the InjectionPoint when you are producing scoped beans. Is there an easy way to do that or some kind of bolg entry or...

Inject CDI managed bean in SystemEventListener

jsf,cdi,managed-bean,systemeventlistener
I have used answer of How to disable elements from within a ViewHandler after jsf has embedded the composite component? to programmatically disable all components in all forms. A SystemEventListener catches and disables all components. What I would like to add is getting some logic from a CDI bean. It...

Using flows in webfragments

cdi,jsf-2.2,flow-scope
I'm trying to build a webapp that includes a webfragment which contains a flow. I started building a standalone version of the webapp I want to use as a webfragment. That's working. After that I converted it to this structure: flow-webfragment\src\main\java\javaclasses.. flow-webfragment\src\main\resources\META-INF\beans.xml flow-webfragment\src\main\resources\META-INF\faces-config.xml flow-webfragment\src\main\resources\META-INF\web-fragment.xml flow-webfragment\src\main\resources\META-INF\resources\META-INF\context.xml...

CDI error: Ambiguous dependencies trying to inject EntityManager

jboss7.x,cdi,entitymanager,jboss-weld
I'm facing a strange error while trying to deploy my EJB 3.1 application in a JBoss 7.1.1 application server: WELD-001409 Ambiguous dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[parameter 1] of [constructor] @Inject public br.com.sigga.siot.dao.masterdata.impl.ProfileDAOImpl(EntityManager)]. Possible dependencies [[Resource Producer Field [EntityManager] with qualifiers [@Any @Default] declared as...

Trigger an action after a certain period of time

java-ee,jboss,cdi
Me and my team are developing a webapplication in Java EE and we were wondering about something. One of our classes has a certain lifecycle, it will advance through stages after certain periods of time. How can we achieve this, how can we do, let's say, 10 minutes after the...

CDI with desktop application

java,cdi,desktop-application
Have some business logic using CDI (@javax.inject.Inject and @javax.persistence.PersistenceUnit). Want reuse it inside desctop application. Added beans.xml into META-INF folder. Set Java 7 as default. Wrote simple class: public class Main { @Inject private static AggregatedUserQueries aggregatedUserQueries; public static void main(String[] args) { System.out.println(aggregatedUserQueries); } } Of course it prints...

resteasy cdi producer null

java,cdi,resteasy,producer
used rest easy and want to manage my entitymanager. have persistence.xml resources and beans.xml in WEB-INF. want to use entitymanager in: public class EntityDao { // @PersistenceContext(unitName = "UserPersistenceUnit") @Inject private EntityManager entityManager; public void add(Object t) { try { System.out.println("start adding4."); if (entityManager == null) { System.out.println("entity manager is...

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

jsf,cdi,el,managed-bean
When trying to reference a managed bean in EL like so #{bean.entity.property}, sometimes a javax.el.PropertyNotFoundException: Target Unreachable exception is being thrown. There seem to be three different kinds of messages: Target Unreachable, identifier 'bean' resolved to null Target Unreachable, 'entity' returned null Target Unreachable, 'null' returned null What do they...

Using causes EvaluationException on Submit but executes properly with standard

maven,jsf,glassfish,cdi,java-ee-7
Development Environment 1.8.0_45 JDK Glassfish 4.1 (latest) Maven 3.3.3 NetBeans 8.0.2 MS SQL 2012 Project Details Maven Enterprise Application 2 EJBs 1 WAR (JSF 2.2 Library from Glassfish) EAR Deployment Problem Statement When I use standard <head></head> tags, everything works properly. My CDI works, values are processed, and the site...

CDI Ambiguous resolution exception

java-ee,cdi
I have three classes defined as below. class A { } class B extends A{ } class C extends A{ } class D{ //Inject class A } I am injecting class A in class D. CDI is throwing Ambiguous resolution exception. what is the right way to solve this ?...

SessionContext not injected when using decorators

java,java-ee,glassfish,ejb,cdi
I'm using Glassfish 4 to deploy an application. It used to have an EJB where the SessionContext is injected via a @Resource annotation. @Stateless @DeclareRoles({"StandardRole1", "StandardRole2"}) public class MyClass implements MyInterface { @Resource private SessionContext ctx; @Override public String getPrincipalName() { return ctx.getPrincipal().getName(); } } This worked fine like it...

CDI: get reference to beanManager via static method

java,cdi,jboss-weld,pax
I use weld+paxcdi on java se. I can get the reference to beanManager using @Inject BeanManager beanManager; However, it's clear that I can use this way only in objects that are managed by CDI container. How can I get reference to beanmanager in object that was created by new?...

Jboss 6 - Deployment failed for CDI enabled bean

cdi,jboss6.x
Created a sample project with CDI as in site CDI Sample, but while try to deploy it in Jboss 6, getting below error.Is there any other lib file need to be include to resolve this issue? Lib jars: javaee-api-7.0.jar javax.inject-1.jar Deployment Error: 2015-02-12 12:25:21,852 INFO [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[192.168.10.119:61928]) and supplies: 2015-02-12...

Scope of Stateless Bean

scope,cdi,postconstruct
I got a stateless bean like the following: @Stateless public class MyBean implements IMyBean { @Inject private SomeClass someClass; @EJB private MyRepository myRepository; @Production @Inject private SomeFacade someWorker; @PostConstruct private void init() { // some logic ... } // some more logic... } IMyBean is annotated with @Local. I am...

Dependency Injection in jersey 2.17

java,jax-rs,cdi,jersey-2.0
I have a resource class @Path("/rest") public class DemoResourceController { @Inject DemoService demoService; @Path("/get/demo") @GET @Produces(APPLICATION_JSON) public Response getDemoLists() { List<String> demoList=demoService.getDemoList(); return Response.ok(demoList).build(); } I tried the answers in the post Dependency injection with Jersey 2.0 if i use compile group: "org.glassfish.jersey.ext.cdi" , name: "jersey-cdi1x" , version: "2.17" compile...

On Java8 I cannot inherit an overriden inherited annotation

java,java-8,cdi
I have an annotation @Qualifier @Inherited @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface InheritedQualifier { public String value(); } and I have four classes that make use of it. Parent which has @InheritedQualifier("original") Child which extends Parent but makes no modification GrandChild which extends Parent and has @InheritedQualifier("override") GreatGrandChild which...

Producer method with Qualifier

cdi,java-ee-7
I´m currently working through a JavaEE7 tutorial and I´ve came to an exercise I can´t solve. I have to split my logging into tech log and operational log using qualifiers. Here´s the class where I define these qualifiers: import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.PARAMETER; import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.RUNTIME; import...

JSF Controller ignores @RolesAllowed annotation

jsf,java-ee,jsf-2,cdi
I have a JSF controller that is Named and SessionScoped like this import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named @SessionScoped public class SomeController { ... adding @RolesAllowed or @DenyAll to the controller has no effect. When this controller invokes EJBs that have the @RolesAllowed annotation, it works properly on those bean calls....

Included CDI-enabled Servlet Fails with ContextNotActiveException: WELD-001303:

java,tomcat,servlets,cdi,weld
I am writing a CDI application that runs on Tomcat. I am using Tomcat 7.0.62 with Weld 2.2.12.Final as the CDI implementation. I am using CDI without JSF. The application consists of a dispatcher servlet that is not CDI enabled. The dispatcher includes the output of a CDI enabled servlet...

Issues with CDI when injecting generic type : Wildfly 8.2.0.Final

jboss,cdi,wildfly,wildfly-8,weld
We are facing weird injection issues in Widfly due to CDI changes. We have interface public interface Command<I, O> { } and many classes implement this interface like this public class ApproveUserRequests implements Command<ApproveUserRequestsRequest, List<String>> { } Application listener classes likes to get list of all classes available and uses...

SessionScoped Managed bean injection is not working [duplicate]

jsf,dependency-injection,cdi,jsf-2.2,managed-bean
This question already has an answer here: NullPointerException while trying to access @Inject bean in constructor 1 answer This is my SessionScoped managed bean : import javax.enterprise.context.SessionScoped; import javax.inject.Named; @Named("clientSessionBean") @SessionScoped public class ClientSessionManagedBean implements Serializable { ... } This is my requestscoped managed bean import javax.enterprise.context.RequestScoped; import javax.inject.Inject;...

Cannot use properly (@Inject)

java,java-ee,cdi
When i try to use @Inject to inject my DAO class, in a manager to make it able to give a gson file to a current address i get this exception when i go to the specific web address.Can someone explain me what is the problem. I thought that the...

Transferring CDI qualifier to injected field

java,java-ee,cdi,java-ee-7
I'm working on a Java EE 7 application in a Wildfly 8.2 container which contains some entites that exist in two data sources. Example: I have a jar with Setting entity: @Entity public class Setting { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotNull private String name; private String value;...

CDI Can't inject FirefoxDriver (Selenium)

selenium,cdi
I'm trying to use CDI to inject firefox when i need it (Avoiding to always configure the driver). But i'm always getting NullPointer. I created a producer for the firefox driver @ApplicationScoped public class FirefoxDriverProducer { @Produces @RequestScoped public FirefoxDriver getDriver() { // Inicia o Firefox pelo Selenium String caminhoFirefox...

Injecting EntityManager always null

java,jpa,cdi,weld
I'm trying to inject an EntityManager into my application using CDI but the EntityManager is null when trying to use it. Here is my code I followed several tutorial on how to inject EntityManager and I use the same code as in those tutorial. @Qualifier @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) public @interface DevDatabase...

@InterceptorBinding / CDI/ EJB 3.2 - problems with injection

java,java-ee,cdi,wildfly-8,java-ee-7
My dev environment is: WildFly 8.1, CDI, EJB 3.2, JDK 1.7. App is packed as an ear archive (one ejb + one war) because probably it gonna have other web modules in the future. I'm struggling with a custom @InterceptorBinding type used inside my EJB stateless bean. @Inherited @InterceptorBinding @Target({...

JSF Property not found exception. porperty not readable

jsf,cdi,el
can someone help out, I just don't get it, the other bean works fine, i'ts just that bean that sucks: BEAN: import java.io.Serializable; import java.util.List; import javax.enterprise.context.SessionScoped; import javax.inject.Named; @SessionScoped @Named class FeedbackController implements Serializable { private static final long serialVersionUID = 1L; private Lecture lecture; private List<Feedback> filteredFeedbacks; public...

CDI Interceptor and transaction propagation

java,cdi
I want to add an CDI Interceptor arround invocation of a EJB method. The EJB is a business service @Stateless who have a CDI DAO injected in it. @Stateless class MyService { @Inject private DAO myDAO; @Workflow @TransactionAttribute(TransactionAttributeType.REQUIRED) public void doStuff(MyData data) { //doing stuff myDAO.edit(data); //doing others DAO stuff...

Jetty Maven plugin (jetty:run goal) + Weld CDI + JSF 2.2 = NPE on ViewScoped beans

maven,jsf,jetty,cdi,weld
Using the following (pretty up to date) components in the web application: Jetty maven plugin 9.2.6.v20141205 Weld CDI 2.2.9.Final Mojarra JSF 2.2.10 The app's web.xml contains the following listeners: org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener com.sun.faces.config.ConfigureListener The first listener registers BeanManager with JNDI. The second listener initializes JSF and looks up for BeanManager in the...

Ambiguous dependency while using @Produces annotation

java,java-ee,dependency-injection,cdi,jboss-weld
I have been studying @Produces annotation of CDI dependency injection from here. I just created my own same example. However, I am facing with ambiguous dependency. public interface Bank { public void withdrawal(); public void deposit(); } public class BankOfAmerica implements Bank { @Override public void withdrawal() { System.out.println("Withdrawal from...

Cannot inject CDI @SessionScoped in HttpSessionListener

jsf,java-ee,cdi,wildfly-8
I have a stateful, session scoped (CDI) EJB that holds the info about the user session. @Stateful @SessionScoped public class GestorSesion implements IGestorSesionLocal, Serializable { private final static long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(GestorSesion.class.getName()); @PostConstruct private void init() { log.info("Configurando información de usuario"); log.info("****************************************************************************"); }...

@Specializes for EJB

ejb,cdi,java-ee-6
I'm trying to specialize an EJB. I have package com.foo.core; @Stateless public class MyFacade { } and package com.foo.extension; @Specializes @Stateless public class MyFacade extends com.foo.core.MyFacade { } In my opinion, this should work, because the meaning of @Specializes is, that CDI should forget about the core-class and instead use...