[
https://issues.jboss.org/browse/WFLY-8942?page=com.atlassian.jira.plugin....
]
Martin Kouba commented on WFLY-8942:
------------------------------------
[~jamezp] Yep, if you execute a batchlet in a different thread you need to *activate* the
request context manually using Weld API, see also
http://weld.cdi-spec.org/documentation/#0 and
http://docs.jboss.org/weld/reference/latest/en-US/html/contexts.html. However, you cannot
propagate the request context bound to an HTTP request. There is an example of using
{{BoundRequestContext}} and an external data store. You could even use {{@Inject @Unbound
RequestContext}} and store the beans in a thread local (see for example
https://github.com/weld/core/blob/2.4/impl/src/main/java/org/jboss/weld/c...).
It depends on your requirements.
It seems the Batch spec is DI technology agnostic, i.e. the active scopes are not defined.
It's probably a good idea to activate the request context during execution of batch
components. However, I'm no batch expert and so I'm not sure about the boundaries
(batchlet execution, etc.).
Request Scope is not active during Batchlet
-------------------------------------------
Key: WFLY-8942
URL:
https://issues.jboss.org/browse/WFLY-8942
Project: WildFly
Issue Type: Bug
Components: Batch, CDI / Weld
Affects Versions: 10.1.0.Final
Environment: Wildfly 10.1.0 Final
Reporter: Cody Lerum
Assignee: James Perkins
Attachments: batch-chunk.war
When executing a Java EE 7 batchlet if an injection of an @RequestScoped bean is
attempted.
Example
{noformat}
20:57:13,995 WARN [org.jberet] (Batch Thread - 13) JBERET000001: Failed to run batchlet
org.jberet.job.model.RefArtifact@b5b6a97:
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for
scope type javax.enterprise.context.RequestScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:689)
at
org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at
org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:165)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at
org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at
org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
{noformat}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)