Results 1 to 4 of 4

Thread: Newbie Spring Service into Action Injection problem

  1. #1

    Default 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"));
    }

  2. #2

    Default

    I see one problem here:
    Code:
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    
    UserDTO userDTO = getUserService().getUser(); // THROWS NPE
    return (mapping.findForward("login"));
    }
    , if you do it like so, you simply are calling 'login forward' without any parameters passed through request, so you have to do something like this:
    Code:
    request.setatribute("user",userDTO.getUser() );

  3. #3

    Default Thanks duardito, but the real problem is the serviceImpl isn't being "read"

    That won't help..

  4. #4

    Default Solved... if anyone cares.. ;)

    The problem was in my struts-config.xml. The type had to be changed to the DelegatingActionProxy.

    <action path="/Login" type="org.springframework.web.struts.DelegatingAct ionProxy">
    <forward name="login" path="tile.tile" />
    </action>

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
  •