cdi

Java - Inject Bean inside method

不问归期 提交于 2019-12-12 05:26:47
问题 I want to inject bean inside my method. I have remote method(Direct Web Remoting) and i need to inject some bean inside this method. I can't use @Inject annotation in field declaration section because it will not work. It is even possible ? 回答1: It could be possible using serious bytecode instrumentation, but that's probably not feasible. Does DWR prevent you from using regular Injection? 回答2: There are lots of ways to do something like this. What container do you run? DWR doesn't seem to

CDI Injection through multiple levels?

为君一笑 提交于 2019-12-12 04:54:07
问题 I am using CDI to initialize a DataSource (See my previous question: DataSource initialization error within liberty profile server) public abstract class DAOBase { @Resource(name="jdbc/Oracle", lookup = "jdbc/Oracle") private DataSource ds; This works well when the DAO class is initialized directly from the REST class: @Path("/audit") public class AuditREST extends RESTBase implements AuditRESTInterface { @Inject private AuditDAO auditDAO = new AuditDAO(); And when the REST class calls an

MyBatis CDI class loader issue in case of EAR

为君一笑 提交于 2019-12-12 04:31:27
问题 I have an EAR which at the moment contains only one WAR. My issue is if the mybatis-....jar files locate under web-module.war\WEB-INF\lib then everything works fine. BUT if I create a skinny war with maven and the two mybatis related jars locate under EAR/lib I get a " There are no SqlSessionFactory producers properly configured. " error. I seems that it is a classpath related issue. I am planning to add more WAR into my EAR and I would like to avoid the situation to put these two jars into

Disable @Alternative classes

a 夏天 提交于 2019-12-12 04:23:11
问题 In my Java EE 7 program, I want to use @Alternative to inject different implementation depending on the context, production or test for example. What I did is to declare my class annotated with @Alternative in my beans.xml file. It works great and my alternative class is injected wherever I want instead of the default one. But I don't know if there is a way to skip this behavior and inject the default class other than removing the declaration in the beans.xml file. Which is not possible

jetty9,spring4.2,hibernate5,omnifaces2.2,can't work - “CDI BeanManager instance is not available in JNDI.”

橙三吉。 提交于 2019-12-12 04:04:57
问题 The application can't startup correctory,the root cause is: java.lang.IllegalStateException: CDI BeanManager instance is not available in JNDI. at org.omnifaces.config.BeanManager.<init>(BeanManager.java:106) at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:49) at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:69) at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89) at org.omnifaces.application

implementing JSF-2.3 and CDI together in WebSphere Application Server

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:02:39
问题 I have recently upgraded to using Oracles new JSF-2.3 which involved adding the dependency as an external library in my pom.xml as I am using maven, As opposed to previously using WebSphere Application server's (WAS) inbuilt JSF-2.2 feature. I wanted to upgrade to make use of the new f:websocket feature which allows me to push messages from server to client for some clever asynchronous page loading. But before we get into that, once I upgraded, I noticed that my @ManagedBean annotations were

How can I inject two EJBs of same type?

∥☆過路亽.° 提交于 2019-12-12 03:59:30
问题 I'm trying to inject two EJBs of same type with different annotation. But the instances injected are same. @Path("/some") public class SomeResource { @Inject @SomePostConstructionAnnotationForSomeService("this") private SomeService s1; @Inject @SomePostConstructionAnnotationForSomeService("that") private SomeService s2; } SomeService class looks like this. public SomeService { @PostConstruct private void constructed() { // find the annotation and do something else. } @Inject private

How to discover a CDI producer in a WAR context?

房东的猫 提交于 2019-12-12 03:54:30
问题 I'm stuck with a CDI problem. I've deployed a war that contains various jars in its WEB-INF/lib folder. One of those jars has a Logger producer (a class with a method which is annotated with @Produces ) and some custom qualifier annotations, some other jars have classes where I want to use the qualifiers and inject Loggers. The idea was to avoid code duplication. But now, to my surprise, WELD complains during deployment, that it has unsatisfied dependencies for the Logger. It looks like, the

@Inject annotation for object and two different behaviors of this object

时光怂恿深爱的人放手 提交于 2019-12-12 03:26:39
问题 I use a JSF 2.2 and CDI. I created below example to show you a heart of my problem. You can see below: the two xhtml pages, the session scoped CDI bean ( LoginController ) which is the controller for the xhtml page1, the view scoped CDI bean ( DataController ) which is controller for the xhtml page2, the request scoped CDI bean ( DataServiceImpl ) which is the service for the DataController bean. This is a use case and flow of the data: xhtml page2 -> the DataController controller -> call

PAX-CDI: how to get reference to BeanManager in bundle without using CDI

谁都会走 提交于 2019-12-12 01:57:32
问题 There is a bundle A and threre is a class MyClass in bundle A. And we suppose that pax-cdi+weld is on. Can can I get reference to BeanManager of the bundle A inside MyClass without using @Inject and other CDI annotations? Via osgi service? Or how? 回答1: You can look up the CdiContainer OSGi service and invoke getBeanManager() . With recent versions of Pax CDI CDI.current().getBeanManager() should work as well. Having said that, the whole idea of Pax CDI is to make CDI work in OSGi just like in