我有一个MVC春天控制器,在进出口文件,我有:
import com.ish.system.dao.UserDAO;
public class CustomImpl implements CustomService {
UserDAO userDAO = null;
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
public String ServiceType(userId) {
User user = userDAO.findById(userId);
...
下面是在控制台中的错误:
SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
java.lang.NullPointerException
at com.ish.smdb.service.impl.CustomImpl.ServiceType(CustomImpl.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
这里是控制器:
@RequestMapping(value="/ServiceType", method=RequestMethod.GET)
public @ResponseBody String ServiceType(
Locale locale,
Model model) {
String result = custom.ServiceType();
return result;
}
这里是bean:
<bean id="Custom" parent="baseTransactionProxy">
<property name="target">
<bean id="CustomImpl" class="com.is.sm.service.impl.CustomImpl">
<property name="userDAO" ref="UserDAO" />
</bean>
</property>
</bean>
为了确保userDAO的为空。 但我没有找到振振有辞。 我是什么问题?