Spring MVC服务实现DAO为空

时间:2014-02-23 17:00:37

标签: java spring spring-mvc

我有一个MVC Spring控制器,在Imp文件中,我有:

import com.is.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);

...

这是我放在applicationContext文件中的bean。

<context:component-scan base-package="com.is.sm.service" />

<bean id="UserDAO" name="userDao" class="com.is.system.dao.impl.UserDAOImpl">
  <property name="sessionFactory">
     <ref bean="annotationSessionFactory" />
  </property>
</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>

以下是控制台中的错误:

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;
}

userDAO为空。但我没有找到原因。我错了什么?

0 个答案:

没有答案