I'm using Websphere Application Server 8.0.0.5 and I've observed the following issues while using CDI.
- Classes which have
@Producer
methods cannot have any scope other than@Dependent
- Any bean whose scope is other than
@Dependent
cannot be injected and used in classes with@Producer
methods.
On doing any of the above task, I get:
[10/8/15 14:50:30:764 GMT+05:30] 00000019 InjectInjecti E CWOWB0102E: A JCDI error has occurred: WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread
[10/8/15 14:50:30:766 GMT+05:30] 00000019 BusinessExcep E CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "doSomething". Exception data: javax.ejb.EJBException: Injection failure; nested exception is: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread
javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ApplicationScoped does not exist within current thread
at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:321)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:124)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:95)
......
Sample code to replicate the issue:
public class Producer{
@Inject
@MyQualifier
private Properties properties;
@Produces
public Logger getLogger(InjectionPoint ip){
System.out.println(properties);
System.out.println("Injection point is: "+ip);
return Logger.getLogger(ip.getMember().getDeclaringClass().getName());
}
}
public class AnotherProducer{
@Produces
@MyQualifier
@ApplicationScoped
public Properties getProperties(){
Popperties p = new Properties();
p.put("key","value");
return p;
}
}
My question here is - Am I violating the CDI spec or there's something wrong with my Container?