cdi

TomEE CDI @Inject NullPointerException

家住魔仙堡 提交于 2021-02-17 02:14:11
问题 I'm trying to get CDI to work in my application, but I only get NullPointerExceptions when I do. When normally instantiating the playlistService, it works perfectly fine, but when I try to use CDI, it doesn't anymore. The server is able to start, but when I add beans.xml to META-INF/ and WEB-INF/ it's also not able to start anymore. PlaylistRESTController.java import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.*; @Path("/api

enable CDI injection into a bean created by a producer method

混江龙づ霸主 提交于 2021-02-11 17:52:23
问题 Producer methods are very useful for creating instances programmatically and publishing them in a context. The problem is that all properties of an instance created by new and returned by a producer method are not injected by CDI. In the Weld documentation I've read that this is an intentional behaviour, but in many cases injection in those beans would be very useful. Is there a workaround to enable injection into such beans? 回答1: First, I have to ask why you are using Producers for beans

CDI context in Kafka de-/serializer in Quarkus app

老子叫甜甜 提交于 2021-02-10 09:24:54
问题 I have a Quarkus project with Smallrye reactive messaging based on Kafka. Since I want to work with a "complex pojo" I need a custom de-/serializer. I'd like to make those two classes CDI beans so I can inject and use my custom logger, which is a CDI bean. Is there a way to achieve this? Right now my injected logger object is simply null: import org.apache.kafka.common.serialization.Serializer; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @ApplicationScoped

CDI context in Kafka de-/serializer in Quarkus app

别等时光非礼了梦想. 提交于 2021-02-10 09:24:51
问题 I have a Quarkus project with Smallrye reactive messaging based on Kafka. Since I want to work with a "complex pojo" I need a custom de-/serializer. I'd like to make those two classes CDI beans so I can inject and use my custom logger, which is a CDI bean. Is there a way to achieve this? Right now my injected logger object is simply null: import org.apache.kafka.common.serialization.Serializer; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @ApplicationScoped

How to start special init event in a backing bean before JSF page loads?

僤鯓⒐⒋嵵緔 提交于 2021-02-07 04:04:38
问题 PF 3.5.10, Mojarra 2.1.21, Omnifaces 1.5 How to call special init()-method of some (CDI)SessionScoped bean before I load a .xhtml JSF page ? Now I call init() if user select the page from site menu (with p:menutitem ). But what to do if the user use browser address line to type url directly? Edit: my.xhtml : <ui:define template="/mytemp.xhtml"> <f:event type="preRenderView" listener="#{mybean.init()}" /> <h:form> <p:commandButton update="@form" ... /> </h:form> </ui:define> If I do it that

How to start special init event in a backing bean before JSF page loads?

不打扰是莪最后的温柔 提交于 2021-02-07 04:01:58
问题 PF 3.5.10, Mojarra 2.1.21, Omnifaces 1.5 How to call special init()-method of some (CDI)SessionScoped bean before I load a .xhtml JSF page ? Now I call init() if user select the page from site menu (with p:menutitem ). But what to do if the user use browser address line to type url directly? Edit: my.xhtml : <ui:define template="/mytemp.xhtml"> <f:event type="preRenderView" listener="#{mybean.init()}" /> <h:form> <p:commandButton update="@form" ... /> </h:form> </ui:define> If I do it that

How to inject two instances of two different classes which implement the same interface?

别说谁变了你拦得住时间么 提交于 2021-01-29 06:21:00
问题 When dealing with CDI in java, I want to inject two instances of two different classes, implementing the same interface. As I understand, I can inject an instance of a class which does not implement an interface, e.g.: class MyClass { // ... } class XY { @Inject MyClass myClass; } When my class implements an interface I have to declare the member by the interface name (and specify the concrete implementation): class MyClass implements MyInterface { // ... } class XY { @Inject MyInterface

What is the meaning of $$$view in java log file?

大兔子大兔子 提交于 2021-01-20 12:52:34
问题 I got an exception with a stack trace containing the following line my.company.Service$$$view26.myMethod(Unknown Source) Can anybody help me to understand what the $$$view part means? We are using JBoss EAP 6.4 and Java 8. 回答1: A dollar sign ( $ , one or multiple) means that it is a generated class. CDI (Weld 1.x in case of EAP 6.4 you are using) is one of the 'frameworks' which uses this pattern. It creates proxies based on your classes in order to allow for interception decoration and bean

Exception using weld CDI with Jetty: Singleton not set for STATIC_INSTANCE

跟風遠走 提交于 2020-12-08 06:20:32
问题 I am trying to configure Jetty with JSF and Weld CDI. After following this manual, I stumble upon the following stacktrace: Caused by: java.lang.IllegalStateException: Singleton not set for STATIC_INSTANCE => [] at org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider$RegistrySingleton.get(RegistrySingletonProvider.java:28) at org.jboss.weld.Container.instance(Container.java:55) at org.jboss.weld.SimpleCDI.<init>(SimpleCDI.java:77) at org.jboss.weld.environment.WeldProvider

CDI beans inside .jar are not found by the container (Unsatisfied dependencies)

最后都变了- 提交于 2020-12-05 05:01:06
问题 I have created a Java project to serve as a lib to other projects, reducing code duplication between projects. This lib project is exported to jar to be included in Web projects (WAR, not EAR). In Web projects (where these classes are being removed) everything worked as usual while all classes were kept on them ─ the injection of simple and complex objects (those with Producers and settings) was working normally. After removing these classes of the Web projects and add the jar with these same