cdi

Subresouce and CDI Injection Issue

孤人 提交于 2019-12-24 11:19:04
问题 I am new to jax-rs and i am stuck with subresources. Take a look. this is not working @Path(..) public class Test { @Path(...) public SubResource getSub(){ return new SubResource(); } } public class SubResource { @Inject private MyBean myBean; @GET public String getStr(){ return myBean.getStr(); // myBean is null, injection didnt work properly } this works, but why???? @Path(..) public class Test { @Context private ResourceContext context; @Path(...) public SubResource getSub(){ return

CDI inject into existing object

旧街凉风 提交于 2019-12-24 10:26:36
问题 Let's say I have the following class: public class MyRequestPayload implements RequestPayload { protected MyRequestPayload() {} @Override public ResponsePayload process() { String result = someService.doSomething(foo, bar); return new MyResponsePayload(result); } public final String foo; public final Integer bar; @Inject private SomeService someService; } Is there some CDI service I can invoke that will process all the @Inject annotations on an instance of this class, injecting all the

BeanManager always returns same reference

拟墨画扇 提交于 2019-12-24 09:07:35
问题 I am creating a custom CDI scope and am using the BeanManager to get an injection of my NavigationHandler custom class. But the beans it returns are quite strange. So I use the BeanManager that way : public class ScreenContext implements Context { private NavigationHandler getNavigationHandler() { final Set<Bean<?>> beans = m_beanManager.getBeans(NavigationHandler.class); final Bean<?> bean = m_beanManager.resolve(beans); NavigationHandler reference = (NavigationHandler) m_beanManager

Add a stateful bean using a producer and polymorphism with CDI in JEE

人走茶凉 提交于 2019-12-24 09:05:44
问题 I'm really new to JEE CDI but tried half of last night to find a solution to a problem. I have a Controller Class that, when startup is called, should inject a stateful bean using a Producer depending on a parameter. This mentioned stateful bean itself contains an injected bean itself. To be honest, not sure if this works at all, any feedback is highly appreciated=) Here is some dummy code that should help understand what I want to do (based oin https://docs.jboss.org/weld/reference/1.0.0/en

Conversation not propagated automatically on form submission?

时光怂恿深爱的人放手 提交于 2019-12-24 06:36:03
问题 I have the following conversation scoped backing bean: @Named @ConversationScoped public class TestConversation implements Serializable { private Logger logger = LoggerFactory.getLogger(TestConversation.class); private List<Integer> numbers; @Inject private Conversation conversation; @PostConstruct public void init() { logger.info("Creating TestConversation bean!!!"); numbers = new ArrayList<Integer>(); numbers.add(3); numbers.add(4); numbers.add(5); numbers.add(6); conversation.begin(); }

CDI invalid bean archive scanning in Jetty (not in Tomcat)

此生再无相见时 提交于 2019-12-24 04:57:08
问题 I thought I got the most about Weld and CDI but this assumption is always demonstrating false. This time I am facing a weird behavior about bean scanning. Everything (a multi-module maven project) runs fine in Tomcat, but I got problems when it runs in the Maven Jetty 9 plugin: java.lang.IllegalStateException: WELD-ENV-000033: Invalid bean archive scanning result - found multiple results with the same reference: /home/myuser/workspace/my-root-project/my-web-module/target/classes at org

ContextNotActiveException in simple Faces Flow with CDI

﹥>﹥吖頭↗ 提交于 2019-12-24 00:49:05
问题 Hy all ! I'm on a simple faces flow tutorial (Tutorial) but can't solve following error: 20:43:32,085 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-14) Error Rendering View[/common/signup/signup.xhtml]: javax.el.ELException: /common/signup/signup.xhtml @17,53 value="#{signup.name}": org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.faces.flow.FlowScoped at com.sun.faces.facelets.el.TagValueExpression.getValue

Startup hangs when using Spring Data repo inside CDI bean

北慕城南 提交于 2019-12-24 00:42:30
问题 I am facing the following issue - my application hangs on startup (no error is given), when trying to access the Spring Data repository from inside the CDI bean. This is my repo: import org.springframework.data.jpa.repository.JpaRepository; public interface ConfigValueRepository extends JpaRepository<ConfigValue, ConfigValueKey> { } where ConfigValueKey: import java.io.Serializable; class ConfigValueKey implements Serializable { private Long keyId; private Long node; } import javax.enterprise

How could I read a JSF session bean from a filter?

大憨熊 提交于 2019-12-23 23:22:13
问题 I'm searching but I can't find the answer, I need secure resources based on permissions, I can't use a filter because FacesContext is not initialized before and I need load the permissions in my session bean. Some solution avoiding use a filter? PhaseListener, ViewHandler and ResourceHandler can't capture an URL resource request, for example I need denied this direct access: http://127.0.0.1:8080/test/resources/images/image.jpg Thx in advance... 回答1: JSF stores session scoped managed beans as

CDI ambiguous dependency when adding @Named qualifier to existing bean via @Produces

冷暖自知 提交于 2019-12-23 23:07:04
问题 I have a CDI bean implementation in a dependency jar file: @ApplicationScoped public class MyService { public String doSomething() {...} } In my webapp, I want to access that service via EL Expression, therefore I have to give it a @Named annotation. But I cannot add the annotation on the MyService implementation because I don't have the rights to change that code. Therefore I tried creating a producer like public class MyServiceProducer { @Inject MyService myService; @Produces @Named(