cdi

Is it possible to inject a CDI Bean into a static variable in Java EE 6?

∥☆過路亽.° 提交于 2019-12-28 07:02:01
问题 Is this possible: @Inject @MessageTransport(MessageTransportType.SMS) public static MessageSender messageSender; I'm getting a NPE when i'm trying to access this static variable. So I wonder, if it is not possible in general. Thanks in advance. 回答1: Not done in general because a static variable cannot have a scope, i.e. it's just one for the whole class (read application) and therefore it doesn't make sense since every instance would try to set it to a new value based on the current scope.

use case for FacesConverter

纵然是瞬间 提交于 2019-12-25 18:33:29
问题 Referencing a previous question of mine, why is the @PostConstruct method not runnable? glassfish gives: INFO: MessageBean.. INFO: MessageBean.getModel.. INFO: SingletonNNTP.getMessages.. INFO: MessageBean.getModel.. INFO: SingletonNNTP.getMessages.. INFO: SingletonNNTP.setIndex..2,205 INFO: SingletonNNTP.setIndex..2,205 INFO: SingletonNNTP.setIndex..2,206 INFO: SingletonNNTP.setIndex..2,206 INFO: SingletonNNTP.setIndex..2,207 INFO: SingletonNNTP.setIndex..2,207 INFO: SingletonNNTP.setIndex.

What is the meaning of @Priority for CDI @Interceptor?

时间秒杀一切 提交于 2019-12-25 16:53:57
问题 1) What is the meaning of @Priority for CDI @Interceptor ? 2) How does it relate to order of interceptors declared in beans.xml ? 3) Can @Priority be overwritten in xml file ? 回答1: 1) Well, as the name suggests, it's meant to set priority (order) to the interceptors within Java EE application. Such interceptor will also be automatically registered so you don't have to define it in beans.xml . 2, 3) JBoss documentation says that interceptors annotated with @Priority ale called before ones

Bootstrap Weld in a Spring Boot environment

自古美人都是妖i 提交于 2019-12-25 12:55:25
问题 Does anyone know a way to bootstrap Weld in a Spring Boot Jar application with embedded Tomcat. I have tried to use org.jboss.weld.environment.servlet.Listener with import org.jboss.weld.environment.servlet.Listener; @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } @Bean public Listener weldListener() { return new Listener(); } } But I get the following error: java.lang.RuntimeException: WELD-ENV

parameter with <f:viewParam> and FacesConverter from CDI

ε祈祈猫儿з 提交于 2019-12-25 11:50:24
问题 It's not clear to me why I'm getting this particular exception, it's a red-herring I think. The underlying problem could be related to the last line of the exception: MessageConverter.getAsObject..0 which should actually be 1501 (the Message ID). So, why does MessageConverter.getAsObject have the wrong id? I think that this could be related to the Detail constructor, which is probably passing the wrong parameters to MessageConvert.getAsObject(), in particular the UIComponent object --

Initializing CDI Bean Name Ambiguous

余生长醉 提交于 2019-12-25 09:05:24
问题 I have a web application running on JSF 2.2 over WebLogic Application server. I have a simple java class and trying to initialize it as an ApplicationScoped object using CDI. The below code works fine and gets deployed. import javax.enterprise.context.ApplicationScoped; @ApplicationScoped public class AppContext { public AppContext() { } } However when I try to initialize the object with @Named annotation, it fails to deploy what so ever import javax.enterprise.context.ApplicationScoped;

CDI (Weld SE) not injecting inner dependencies when using Producer method

我的未来我决定 提交于 2019-12-25 08:30:14
问题 I'm using WELD SE on a standalone java project which seemed to work fine till I started using producers. The producer method works - the container uses it, but never injects the inner pdependencies of the produced bean. When I remove the producer, it works normally. I can't find the cause even after a long search on the spec and on Google. Example of a Producer: @ApplicationScoped public class LaminaValidadorProducer { private static final String XSD_PATH = getConfig("processador.xsd.path");

Injection CDI of Interface Returns NullPointerException

女生的网名这么多〃 提交于 2019-12-25 07:59:26
问题 I have a problem with the injection in Java as I would like to inject an interface called RemoteStatisticService but it keeps returning null in this case thus error NullPointerException. I have tried to follow this with init() method and @PostConstruct but still gives me the same error. Here is the code for MeasurementAspectService class: import javax.annotation.PostConstruct; import javax.inject.Inject; import *.dto.MeasureDownloadDto; import *.dto.MeasureUploadDto; import *.rs

WELD-001408: Unsatisfied dependencies for type HttpSession

时间秒杀一切 提交于 2019-12-25 07:39:30
问题 I have this (notorious by now) @SessionScoped bean in my JSF project: @Named(value = "appointmentFormBean") @SessionScoped public class AppointmentFormBean implements Serializable { @Inject private transient AppointmentService service; public AppointmentFormBean() { bookedAlready = new ArrayList<>(); types = new LinkedHashMap<>(4, (float) 0.75); } public AppointmentService getService() { return service; } public void setService(AppointmentService service) { this.service = service; } ... /

M2E Eclipse Maven Workspace resolution and CDI

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:24:45
问题 I have a war project A that I am deploying to JBoss AS7 that uses CDI and all works fine. But I want to use some classes in another project B, which I added to my pom.xml and turned on workspace resolution for, because these classes will be shared by multiple war projects. Now these classes work perfectly fine as long as they are in the war project A, but when I move them to B, the CDI on them stops working. The other project B has a webapp/WEB-INF/beans.xml, but when looking at the deployed