1. won't work since it is happening at pipeline construction time and not
pipeline execution time.
2. only works if your application context is scoped to the DoFn instance
and doesn't have things you want to possibly share across DoFn instances.

You could also try and make it a PipelineOption that is tagged
with @JsonIgnore and also has a @Default.InstanceFactory like this[1]. This
way when it is accessed by your DoFn it will be initialized for the first
time and shared within your process. Making it a PipelineOption would also
allow you to pass in preinitialized versions for testing.

1:
https://github.com/apache/beam/blob/8267c223425bc201be700babbe596d133b79686e/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/options/GcpOptions.java#L127

On Wed, Oct 9, 2019 at 1:10 PM Jitendra kumavat <jkumavat1...@gmail.com>
wrote:

> Hi Luke,
>
> Thanks a lot for your reply.
> I tried couple of options which is as follows.
>
> 1. Initialise the context in main method only. and use it.  Creating the
> context:
>     new AnnotationConfigApplicationContext(AppConfig.class);
> 2. Creating the context on DoFn.Startup method.
>
> Unfortunately none of the worked perfectly, later works but it has issue
> with @ComponentScan.
> Please let me know your comments for the same.
>
> I will also try this JvmInitializer for context initialisation.
>
> Thanks,
> Jitendra
>
> On Wed, Oct 9, 2019 at 12:48 PM Luke Cwik <lc...@google.com> wrote:
>
>> -d...@beam.apache.org, +user@beam.apache.org
>>
>> How are you trying to inject your application context?
>> Have you looked at the JvmInitializer.beforeProcessing[1] to create your
>> application context?
>>
>> 1:
>> https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/harness/JvmInitializer.java
>>
>>
>>
>>
>> On Fri, Oct 4, 2019 at 12:32 PM Jitendra kumavat <jkumavat1...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> I want to add Spring framework in my apache beam project.  Somehow i am
>>> unable to inject the Spring Application context to executing ParDo
>>> functions. I couldn't find the way to do so? Can you please let me know how
>>> to integrate Spring runtime application context with Apache Beam pipeline.
>>>
>>> Thanks,
>>> Jitendra
>>>
>>

Reply via email to