For some reason, in my config package, I can not autowire fields while in my controller package, there does not seem to be any problem.
For instance:
servlet-context.xml
<context:component-scan base-package="service, controller, config" />
root-context.xml (tried adding service here as well)
<context:component-scan base-package="security" />
This does not work: Setup class inside the config package. I receive a null pointer error.
@Component
public class Setup { //inside the config package
@Autowired
private UserService userService; //null pointer error
/*..other stuff */
}
This does work: A controller inside the controller package:
@Controller
@RequestMapping(value="/contact")
public class ContactController { //inside the controller package
@Autowired
private UserService userService; //this works
/*..other stuff..*/
}
Why does it work for the controller package but not config package?