Java+Spring: SEVERE Servletservice

前端 未结 4 1148
孤街浪徒
孤街浪徒 2021-01-17 04:14

I dont know what is wrong in my listContacts in controller map.put(\"contactList\", contactService.listContact()); Can somebody help me?

相关标签:
4条回答
  • 2021-01-17 04:27

    I think you are missing to add the contactService bean to your applicationContext.xml try adding the below to tags

    <bean id="contactService" class="pl.ivmx.contact.service.ContactServiceImpl">
    <property name="contactDAO" ref="contactDAO" />
    </bean>
    
    <bean id="contactDAO" class="pl.ivmx.contact.dao.ContactDAOImpl" />
    
    0 讨论(0)
  • 2021-01-17 04:35

    It looks like a NullPointerException thrown in the method here:

    @RequestMapping("/contact")
    public String listContacts(Map<String, Object> map) {
        map.put("contact", new Contact());
        map.put("contactList", contactService.listContact());       
    
        return "/contact";
    }
    

    I would debug and check that contactService has been autowired correctly.

    The null pointer is line 26, if that is the line containing contactService.listContact() then contactService is null. If it is the line above then the map is null.

    I am not sure but try adding:

    <context:component-scan base-package="pl.ivmx.contact" />

    to the dispatcher-servlet.xml as well, it could be that the annotation isnt getting processed

    0 讨论(0)
  • 2021-01-17 04:37

    I don't see anything obvious ... could sessionFactory be null? Should be easy to find, tho. Step through the code in the debugger.

    0 讨论(0)
  • 2021-01-17 04:39

    you are returning "/contact" there in the method as a view to be shown:

    @RequestMapping("/contact")
    public String listContacts(Map<String, Object> map) {
        map.put("contact", new Contact());
        map.put("contactList", contactService.listContact());       
    
        return "/contact"; // <---- here!
    }
    

    This means that you should have a view named /contact defined somewhere, but I don't see it. You need to have a view that corresponds with the value you're defining.

    You probably want to return a value like "contact" instead of "/contact" and then have contact.jsp in the webapp/WEB-INF/views folder (assuming you use maven standard directory layout).

    0 讨论(0)
提交回复
热议问题