Question: How I can inject my `webServiceTemplate` in the implementing class?

My example:

```
public abstract class AbstractConnector {

    protected WebServiceTemplate webServiceTemplate;

    protected Object send(Object message) {
        return webServiceTemplate.marshalSendAndReceive();

   }

```

}

And in my concrete implementation I would like to set my `webServiceTemplate` like this.

```
public class MyConnector extends AbstractConnector {

   @Resource(name = "myWebService")
   private WebServiceTemplate webServiceTemplate;
}

```

But this is not OK. If I call the `send()`, then I will get NPE because `webServiceTemplate` is null. How to set this dependency in implementation which will be accessible in the `send()` method?

Answer: 
It's best to avoid field injection whenever possible, and this is an example why. Constructor injection makes this simple:

```
public abstract class AbstractConnector {
    private final WebServiceTemplate webServiceTemplate;

    protected AbstractConnector(WebServiceTemplate webServiceTemplate) {
        this.webServiceTemplate = webServiceTemplate;
    }
}

@Service
public class MyConnector extends AbstractConnector {

    @Inject // or @Autowired
    public MyConnector(@Qualifier("myWebService") WebServiceTemplate webServiceTemplate) {
        super(webServiceTemplate);
    }
}

```
You can use `method-lookup`:

You abstract class:

```
public abstract class AbstractConnector 
{

private abstract WebServiceTemplate getWebServiceTemplate();

protected Object send(Object message) 
{
    return getWebServiceTemplate().marshalSendAndReceive();
}

```

Your configuration:

```
   <bean id="webServiceTemplate" scope="prototype" class="com.example.WebServiceTemplate" />
   <bean id="connector" class="com.example.AbstractConnector"
        <lookup-method name="webServiceTemplate" bean="webServiceTemplate" />
    </bean>

```

Spring will wire you abstract class to return a fresh `webServiceTemplate` if the method `getWebServiceTemplate()` is called.