Announcement Announcement Module
Collapse
No announcement yet.
Newbie Spring Service into Action Injection problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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() );

    Comment


    • #3
      Thanks duardito, but the real problem is the serviceImpl isn't being &quot;read&quot;

      That won't help..

      Comment


      • #4
        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>

        Comment

        Working...
        X