3

I have a prototype bean factory (CreateCarAction is spring bean, scope=prototype):

@Component("createCarActionFactory")
public abstract class CreateCarActionFactory  {

    @Lookup
    public abstract CreateCarAction createCarAction();
}

and I Autowire it like this:

@Autowired
@Qualifier("createCarActionFactory")
private CreateCarActionFactory createCarActionFactory;

It works when I remove abstract from CreateCarActionFactory. When I remove abstract I must implement createCarAction() - I don't need this implementation as @Lookup overrides it. When I resign from CreateCarActionFactory I must access CreateCarAction form beanFactory, so I jave to Autowire beanFactory, which is also ugly..

Can I autowire abstract CreateCarActionFactory @Component?

Maxim
  • 52,561
  • 27
  • 155
  • 209
michealAtmi
  • 1,012
  • 2
  • 14
  • 36
  • Why wont you use Provider? ```Provider createCarActionProvider;``` and then you just do ```createCarActionProvider.get()```. – hya Mar 01 '17 at 21:06
  • 2
    You cannot autowire abstract class - http://stackoverflow.com/a/15971422/1814524 – hya Mar 01 '17 at 21:08
  • hya - I don't understand, where would be the implementation of such Provider? How would it create new class with autowired 2 spring beans? This is the reason why I use Lookup.. – michealAtmi Mar 02 '17 at 11:21

1 Answers1

0

You can autowire an interface, so change CreateCarActionFactory from abstract class into an interface.

Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77
  • NoSuchBeanDefinitionException: No qualifying bean of type [mypackage.CreateCarActionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} – michealAtmi Mar 02 '17 at 11:09