0

I am using Spring Boot in my project that runs a Pig script. I have defined a Pig UDF. I wonder whether I can inject a bean into this UDF class. The UDF class is something like this: The UDF that works now looks like this:

public class MyUDF extends EvalFunc<String> {
    public String exec(Tuple input) throws IOException {
        final ClassA instanceA = new ClassA();
        return instanceA.func(input);
    }
}

I wonder whether I can leave the instantiation of instanceA to spring container? I tried

public class MyUDF extends EvalFunc<String> {

    @Autowired
    private final ClassA instanceA;

    public String exec(Tuple input) throws IOException {
        return instanceA.func(input);
    }
}

and also defined a constructor, but neither of these two methods works. Is it because this instanceA should be static?

Is there a way to use Bean factory in Pig UDF?

larueroad
  • 167
  • 8
  • What annotation do you have on `ClassA`? Can you show us the definition of `ClassA`? – Ortomala Lokni Apr 19 '20 at 13:02
  • When I tried it myself, I created a configuration class ``` @Configuration public class AppConfig { @Bean public ClassA instanceA { return new ClassA(); } } ``` – larueroad Apr 19 '20 at 16:33

0 Answers0