cdi

Injecting a SessionScoped Stateful bean in EntityListener

旧时模样 提交于 2019-12-10 13:44:58
问题 I'm trying to implement some sort of auditing in a Java EE JPA application on GlassFish 3. I have added a @EntityListeners annotation on my @MappedSuperclass entity, the listener has the @PrePersist and @PreUpdate annotation on its methods which are invoked happily at runtime. In these methods, I'm trying to use ( @Inject ) a @Named , @Stateful , @SessionScoped bean ( UserSession ) in order to get current user's id. The listener class has no annotations at all. The problem is that I can't get

Why @Singleton over @ApplicationScoped in Producers?

不问归期 提交于 2019-12-10 13:39:37
问题 LoggerProducer.java is a class used to produce Loggers to be injected in CDI beans with: @Inject Logger LOG; Full code: import javax.ejb.Singleton; /** * @author rveldpau */ @Singleton public class LoggerProducer { private Map<String, Logger> loggers = new HashMap<>(); @Produces public Logger getProducer(InjectionPoint ip) { String key = getKeyFromIp(ip); if (!loggers.containsKey(key)) { loggers.put(key, Logger.getLogger(key)); } return loggers.get(key); } private String getKeyFromIp

How to inject EJB into SOAPHandler?

本小妞迷上赌 提交于 2019-12-10 13:39:18
问题 My JAX-WS war contains following entries. WEB-INF/lib/ WEB-INF/beans.xml // empty WEB-INF/lib/commons-logging-1.1.1.jar WEB-INF/lib/corrs-beans-1.0-alpha-1-SNAPSHOT.jar // EJBs are here WEB-INF/lib/corrs-entities-1.0-alpha-1-SNAPSHOT.jar WEB-INF/lib/joda-time-1.6.2.jar WEB-INF/lib/opensaml-2.5.1-1.jar WEB-INF/lib/openws-1.4.2-1.jar WEB-INF/lib/slf4j-api-1.6.1.jar WEB-INF/lib/wss4j-1.6.8.jar WEB-INF/lib/xmlsec-1.5.3.jar WEB-INF/lib/xmltooling-1.3.2-1.jar WEB-INF/web.xml META-INF/maven/ META

Using Jersey 2.1 with CDI

痴心易碎 提交于 2019-12-10 13:30:33
问题 I try to use Jersey 2.1 and CDI in my Java EE 7 project which is deployed on Glassfish 4.0. Jersey modules depend on Guava libraries. But using Guava libraries (14.0.1) with CDI results the following exception being thrown. CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]

Seed value in Weld CDI custom scope

给你一囗甜甜゛ 提交于 2019-12-10 12:57:01
问题 Coming from a Guice background, I know that it is possible to seed an object value from a scope using. scope.seed(Key.get(SomeObject.class), someObject); I suppose one could do this by registering a Bean that gets a value from an AbstractBoundContext , but examples just seeding one value from a Custom Scope seem hard to find. How do I create a custom scope that seeds a value that can be injected elsewhere? Edit: I am currently using the following workaround, that can be injected in an

CDI injection is not working in Servlets

為{幸葍}努か 提交于 2019-12-10 12:56:03
问题 I really need your help. I'm working on this problem for weeks or months now. I apologize for the long post, but I want to explain the problem and my settings as precisely as possible. My JAVA EE 6 web application mainly contains 3 Servlets: a javax.faces.webapp.FacesServlet , a StreamingServlet extending javax.servlet.http.HttpServlet and a ClientServlet extending org.eclipse.jetty.websocket.WebSocketServlet . I want to use CDI with these Servlets but it only works for the FacesServlet, to

WARNING: Parameter 1 of type List<Bean<?>> from public void org.omnifaces.cdi.eager.EagerBeansRepository.setXxx is not resolvable to a concrete type

早过忘川 提交于 2019-12-10 12:50:03
问题 I'm using Omnifaces 1.8.1 and Whenever I deploy my application to Glassfish I get the following warning which causes some delay in the deploy process. Warning: WELD-001519 An InjectionTarget implementation is created for an abstract class org.omnifaces.eventlistener.DefaultHttpSessionListener. It will not be possible to produce instances of this type! Warning: WELD-001519 An InjectionTarget implementation is created for an abstract class org.omnifaces.eventlistener

How to inject mocks while testing classes using CDI in production

…衆ロ難τιáo~ 提交于 2019-12-10 12:41:33
问题 I am programming in a Java SE environment using WELD-SE for dependency injection. Therefore dependencies of a class look something like this: public class ProductionCodeClass { @Inject private DependencyClass dependency; } When writing a unit test for this class I am creating a mock for DependencyClass and as I don't want to start a complete CDI environment for every test I run, I "inject" the mock manually: import static TestSupport.setField; import static org.mockito.Mockito.*; public class

Inject Instance<Interface> : Spring and CDI compatibility

≯℡__Kan透↙ 提交于 2019-12-10 12:01:28
问题 I am wondering how can I use the Instance in JUnit4 with Spring @Inject Instance<IMyInterface> interfaces; If I use @Inject List<IMyInterface> interfaces; It works in Spring but not with CDI. Also, we can use Provider with both CDI and Spring but it's not Iterable. 回答1: The @Inject annotation comes from JSR-330-Dependency Injection for Java. Spring knows this annotation and briefly said, Spring treats it as an alternative to @Autowired . That's it. However, the Instance is part of JSR 299 -

JSF 2.0 CDI - injected session bean within request bean contains null properties

青春壹個敷衍的年華 提交于 2019-12-10 11:58:54
问题 I'm using JSF 2.0, CDI 1.0 within WebSphere App Server v8.0.0.5. I have a bizarre situation... Upon successful login, a CDI session-scoped bean is created, and the user is redirected to a welcome page. The session-scoped bean is injected into a request-scoped bean referened on the welcome page. The problem is that the session-scoped bean ONLY retains its field values upon first successful login per browser. I've tried the same user using Chrome, Firefox, and even IE. If I log out or restart