Hi
I have a problem with class ImportUserFromExternalSourceAD, userDAO cant be injected, i getting NPE
Here is a details (i hope) description of my problem:
Code:package org.system.server; @Service("UserService") public class UserServiceImpl extends RemoteServiceServlet implements UserService { @Autowired ImportUserFactory importUserFactory; @Override public List<BaseModel> getUsersFromExternalStore(AuthmethodDTO storeType) { return importUserFactory.get(authmethod).get(); } }
Code:package org.system.server.dao; public abstract class ImportUserFactory { public abstract ImportUserFromExternalSource get(Authmethod authmethod); }Code:package org.system.server.dao.impl; i @Repository public class ImportUserFactoryImpl extends ImportUserFactory{ @Override public ImportUserFromExternalSource get(Authmethod authmethod) { if(authmethod.getType().equals("ad")){ ImportUserFromExternalSource source = new ImportUserFromExternalSourceAD(); source.setAuthmethod(authmethod); return source; } return null; } }Code:package org.system.server.dao; public interface ImportUserFromExternalSource { public void setAuthmethod(Authmethod authmethod); public List<User> get(); }
So here i get NPE in userDAO.listUser("any");
Code:package org.system.server.dao.impl; @Repository public class ImportUserFromExternalSourceAD implements ImportUserFromExternalSource{ @Autowired private UserDAO userDAO; @Override public List<User> get() { for(User u: userDAO.listUser("any")) System.out.println(u.getFirstName()); } }
applicationContext.xml
In other classes everything's ok so i think the problem in ImportUserFactoryImpl where i return source:Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <context:component-scan base-package="org.system.server" /> <context:annotation-config/> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- i have remove all about hibernate here--> </beans>
ImportUserFromExternalSource source = new ImportUserFromExternalSourceAD();
Thanks for any help


Reply With Quote