inor
inor

Reputation: 2846

How do you cause Spring to inject into/call setters of a Spring annotated class?

is there a way to add annotations to the class below to specify to Spring to inject into the instances a bean for bar?

@Scope("prototype")
@Component("vnetwork-start")
//how to inject bar value?
public class VNetworkStartCommand extends VNetworkCommand { 
    public VNetworkStartCommand() { super(VNetworkCommandType.START); }

    @Required public void setBar(Bar bar) { System.out.println("bar="+bar); }   
}

Upvotes: 0

Views: 39

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

Annotate the method with Spring's @Autowired, or javax.inject's @Inject, or javax.annotation's @Resource.

This obviously assumes that annotation configuration is enabled and a Bar bean is available in the context.

Upvotes: 1

Related Questions