2

I want to inject result of method call to my class. I have next code:

class Example {
    private static final String NAME = "name";

    // #1
    @Autowired
    @Qualifier("a.b")
    private B b;    

    // #2
    @Autowired
    @Qualifier("#{a.b}")
    private B b;

    // #3
    @Autowired
    @Qualifier("#{a.b.getC('" + NAME + "')}")
    private C c;
}

So I have 3 different variants. First one is working, second one is not working but not sure whether I wrote SpEL correctly and third one is not working too.

Actually what I need is third variant. I need to inject result of calling method "getC(name)" on bean called "a.b"

Maybe somebody had similar problem and know how to do it?

Orest
  • 6,548
  • 10
  • 54
  • 84
  • Maybe this can be useful for you: http://stackoverflow.com/questions/19225115/how-to-do-conditional-auto-wiring-in-spring – Sándor Juhos Aug 03 '16 at 11:18

1 Answers1

0

you can't use SpringEL in @Qualifier,and can only use constant in SpringEL.

inject result of calling method "getC(name)" on bean called "a.b" like this:

@Bean(name="a.b")
private B b(){
   return getC(name);
}
pkpk1234
  • 87
  • 1
  • 2