I know theres a ton of questions regarding problems with Spring Autowired, but I havent been able to find anything similar to mine, so sorry if its a dupe...
Im having problems with autowiring a bean that is created (debugging shows that the constructor is run), but then it doesnt get injected. There are no calls of manual instantiation. I have many other autowired fields in the project and they work fine. Most amusing, though, is the fact that Ive used the same pattern and config in a different project and it works there...
Now then, here are the codes:
The bean that gets created but not injected:
@Component("genericDao")
public class GenericHibernateJpaDao implements GenericDao {
@Autowired
protected EntityManagerFactory entityManagerfactory;
public GenericHibernateJpaDao() {
}
//getters, setters and dao methods
}
GenericDao interface only defines methods and has no annotations.
Service super-class that defines the bean:
@Configurable
public abstract class AbstractService {
@Autowired
protected GenericDao genericDao;
//getters, setters
}
Service implementation (declaration bit):
@Service
@Component
public class WechatMessageService extends AbstractService implements IMessageService {
Breakpoint in service implementation at genericDao.saveOrUpdate(n);
shows genericDao to be null (this is also the line that throws NullPointerEx.)
IMessageService is
@Service
@Configurable
@Transactional
application-config.xml (relevant bits):
<beans .......... default-autowire="byName">
<context:component-scan base-package="package.with.dao" />
<context:component-scan base-package="package.with.service" />
<context:spring-configured/>
Im guessing its just some fairly stupid mistake on my side, but I just cant figure it out and googling isnt helping.
Thanks for any help.