-
Aug 22nd, 2009, 12:26 AM
#1
Newbie Spring Service into Action Injection problem
I'm getting a null pointer from my service I have injected into my action--everything seems to be wired? Stuck.. can anyone PLEASE help?? Thanks in advance!!!
service.xml:
<beans>
<bean id="userService" class="service.user.UserServiceImpl"/>
</beans>
service interface class:
public interface UserService {
public UserDTO getUser();
}
serviceImpl class:
public class UserServiceImpl implements UserService {
public UserDTO getUser() {
// TODO Auto-generated method stub
UserDTO userDTO= new UserDTO();
userDTO.setUserId("jdoe");
userDTO.setUserName("John Doe");
return userDTO;
}
}
action.xml
<bean name="/loginAction" class="action.login.LoginAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<bean id="userService" class="service.user.UserServiceImpl"/>
Action Class
public class LoginAction extends BaseAction {
private static final Log log = LogFactory.getLog(LoginAction.class);
private UserService userService;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
UserDTO userDTO = getUserService().getUser(); // THROWS NPE
return (mapping.findForward("login"));
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules