I have an app that's been working well with @Autowired
@Service
beans.
Now I'm adding a Validator
class which is instantiated in the Controller:
BlueValidator validator = new BlueValidator(colors);
validator.validate(colorBlend, bindResult);
In the BlueValidator
class I'm trying to @Autowire the blendService
which is working as an @Autowired
field elsewhere in the app:
public class BlueValidator implements Validator {
@Autowired
private BlendService blendService;
private Colors colors;
But for some reason after instantiating the BlueValidator, I keep getting NullPointerException
s for the blendService
.
Of course I've added the necessary context scanning:
<context:component-scan
base-package="com.myapp.controllers, com.myapp.services, com.myapp.validators" />
I also tried adding the@Autowired
annotation to the constructor but that didn't help:
@Autowired
public BlueValidator(Colors colors) {
this.colors = colors;
}
Should I just pass the blendService
to the BlueValidator
and forget about the Autowiring or is there something obvious missing here?