[cdi-dev] [weld-dev] How to skip CDI injection if a property is not configured in batch application?
jharting at redhat.com
Mon Mar 9 05:32:48 EDT 2015
How do you obtain the current value of a field from an InjectionPoint?
Do you use proprietary APIs for that?
On 03/09/2015 09:52 AM, Mark Struberg wrote:
> There is an easy trick though which we do at BatchEE:
> The producer is @Dependent. So you can simply inject the InjectionPoint and inspect the current value in case it is not yet set.
>> Am 09.03.2015 um 07:25 schrieb Jozef Hartinger <jharting at redhat.com>:
>> Adding weld-dev.
>> Hi Cheng,
>> by defining a producer method you are basically saying "I am able to supply an object for this given type/qualifier combination". There is not way to opt out of it at runtime. Are you concerned about the JVM default values or the default values a user has provided?
>> On 03/07/2015 05:54 PM, Cheng Fang wrote:
>>> Hi Jozef,
>>> I'm having a question in using CDI injection in project JBeret (batch impl project), and would appreciate any help from you.
>>> A batch application (in Java SE or EE) can inject configured batch properties into batch artifact classes:
>>> @javax.batch.api.BatchProperty(name = "batchPropName")
>>> String batchPropName = "default name";
>>> The property value comes from job.xml, which is the batch job definition descriptor file:
>>> <batchlet ref="batchlet1">
>>> <property name="batchPropName" value="configured name"/>
>>> When "batchPropName" property is not configured in job.xml, the injection should not happen, and whatever java default field value should be preserved for batchPropName field.
>>> With our current batch CDI extension  and producer bean , it injects a null value into this field, overwriting the java default value, when the target batch property is not present.
>>> How to signal to Weld to skip performing the injection for those injection targets? Ideally, I hope it can be done from within producer methods, which is the place we retrieve batch properties and know whether they exist or not.
>>> I think this is also how Java EE field injection works. How do we handle it in EE, and is it something I can mirror?
>>>  https://github.com/jberet/jsr352/blob/master/jberet-core/src/main/java/org/jberet/creation/BatchCDIExtension.java
>>>  https://github.com/jberet/jsr352/blob/master/jberet-core/src/main/java/org/jberet/creation/BatchBeanProducer.java
>> weld-dev mailing list
>> weld-dev at lists.jboss.org
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
More information about the cdi-dev