Results 1 to 8 of 8

Thread: Using spring context in mapper, how to autowire

  1. #1

    Default Using spring context in mapper, how to autowire

    What is recommended to use Spring container in mapper?

    In hadoop mapper, i do not have object creation under control. Hadoop will create mapper object and then call its initialization method. I would like to use @Inject in mapper, it means to create application context by hand, this is fine with me, but how to get application context to autowire resources into already created object?

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    We don't support this scenario in master but there's a branch you might want to try that adds this ability.
    In a nutshell, you need to deploy Spring on all nodes and use a Utility mapper (potentially as a base class) that bootstraps Spring from a well-known location and then applies self-injection or autowiring.
    As for the autowiring process, see AutowireCapableBeanFactory & co [1]

    http://j.mp/MoWmI3
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    Thanks for reply, branch is here: https://github.com/SpringSource/spri...doop/mapreduce

    Last commit to this branch is 8 months old. This POJO design pattern was abandoned or there are plans to merge it with current version or place that code in separate module?

  4. #4

    Default

    I am using in Mapper this
    springcontext.getAutowireCapableBeanFactory().auto wireBean(this);

    but no autowiring is done. Fields annotated with @Inject are still null and no error message.

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Do you have javax.inject in the classpath (that is on each cluster node)? You could try @Autowired as a replacement.
    If the annotation library is not found, its declaration is simply ignored.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6

    Default

    javax.inject is part of hadoop since 0.23 (hadoop-2).

    ls $YARN_HOME/share/hadoop/mapreduce/lib/javax*
    /usr/local/hadoop/hadoop-0.23.3-SNAPSHOT/share/hadoop/mapreduce/lib/javax.inject-1.jar

    its listed as guice dependency
    [INFO] +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:0.23.3-SNAPSHOT:provided
    [INFO] | +- org.apache.hadoop:hadoop-yarn-common:jar:0.23.3-SNAPSHOT:provided
    [INFO] | | +- org.apache.hadoop:hadoop-yarn-api:jar:0.23.3-SNAPSHOT:provided
    [INFO] | | +- com.google.inject:guice:jar:3.0:provided
    [INFO] | | | \- javax.inject:javax.inject:jar:1:provided

    No difference with @Autowired but maybe i should call something different then autowireBean(this); there is lot of similar functions in autowirecapablebeanfactory

  7. #7

    Default

    springcontext.getAutowireCapableBeanFactory().auto wireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); didnt worked either

  8. #8

    Default

    i didnt had context annotation processing turned on in XML file. now it works in combination with autowirebeanproperties

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •