问题描述
自己在搭一个mvc框架,在加入mybatis之后访问页面时错误信息如下:type Exception reportmessage Request processing failed; nested exception is java.lang.NullPointerExceptiondescription The server encountered an internal error that prevented it from fulfilling this request.exceptionorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:620) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)root causejava.lang.NullPointerException zhha.controller.WelcomeController.Welcome(WelcomeController.java:21) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:620) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)请问这是什么问题引起的,希望得到一些解决方法的指点。附件为整个框架包。UserService.javapackage zhha.service;import java.util.List;import zhha.dao.UserDao;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import zhha.model.User;@Servicepublic class UserService {@Autowiredprivate UserDao userDao;public List<User> showUser(){userDao.select();List<User> userList = userDao.select(); return userList;}}User.javapackage zhha.model;import java.io.Serializable; public class User implements Serializable { /** * */private static final long serialVersionUID = 1L;private String id; private String name; private String password;public String getId() {return id;}public String getName() {return name;}public String getPassword() {return password;}public void setId(String id) {this.id = id;}public void setName(String name) {this.name = name;}public void setPassword(String password) {this.password = password;}} UserDao.javapackage zhha.dao;import java.util.*;import zhha.model.User;public interface UserDao{public List<User> select();}UserController.javapackage zhha.controller;import java.util.List;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import zhha.model.User;import zhha.service.UserService;;@Controller@RequestMapping("/")public class WelcomeController {private UserService userService;@RequestMapping({"/welcome","/"})public String Welcome(){List<User> users = userService.showUser(); System.out.println(users.size());return "/welcome";}@RequestMapping("/hello")public String Hello(){ System.out.println("hello--------------------"); return "/hello";}}
解决方案
这里private UserService userService; 没有自动注入啊