u010626381
u010626381
2017-07-05 10:41

求各位大牛解决ssm 框架service注入dao为空

  • java

controller:

package com.haier.rrs.controller;

@Controller

@RequestMapping("/register")

public class RegisterController {
@Autowired
private UserService userService;

   @RequestMapping("/doregister.do")  
   @ResponseBody
    public String doregister(HttpServletRequest request){  
        String username = request.getParameter("username");  
        String pwd = request.getParameter("password");   
        EndecryptUtils endecrypUtil =new EndecryptUtils();
        User user=endecrypUtil.md5Password(username, pwd);
        int n=userService.registerUser(user);
        return "/success.jsp";
    }  

}

service层 接口service已经@service:

package com.haier.rrs.service.impl;

public class UserServiceImpl implements UserService{

private UserDao userDao;

public UserDao getUserDao() {
    return userDao;
}

public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
}

@Override
public User doUserLogin(User user) {
    // TODO Auto-generated method stub
    return userDao.doUserLogin(user);
}

@Override
public int  registerUser(User user) {
    // TODO Auto-generated method stub、
    String username="1";
    List<User> lt = new ArrayList();
    lt=userDao.selectAll();
    List<User> us=userDao.selectId(username);
    int n=userDao.addUser(user);
    return n;
}

}

Dao层:

package com.haier.rrs.dao;

@Repository
public interface UserDao {

    List<User> selectId(@Param(value = "username") String username);
    public User doUserLogin(User user);
    public int addUser(User user);
    List<User> selectAll();

}

spring-user.xml

<bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean" parent="baseDAO">
    <property name="mapperInterface" value="com.haier.rrs.dao.UserDao" />
</bean>
<!-- Service -->
<bean id="userService" class="com.haier.rrs.service.impl.UserServiceImpl">
        <property name="userDao" ref="userDao"/>
</bean>

spring-mybatis.xml

<bean id="propertyConfigurer"  
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
    <property name="location" value="classpath:jdbc.properties" />  
</bean>  

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
    destroy-method="close">  
    <property name="driverClassName" value="${driver}" />  
    <property name="url" value="${url}" />  
    <property name="username" value="${username}" />  
    <property name="password" value="${password}" />  
    <!-- 初始化连接大小 -->  
    <property name="initialSize" value="${initialSize}"></property>  
    <!-- 连接池最大数量 -->  
    <property name="maxActive" value="${maxActive}"></property>  
    <!-- 连接池最大空闲 -->  
    <property name="maxIdle" value="${maxIdle}"></property>  
    <!-- 连接池最小空闲 -->  
    <property name="minIdle" value="${minIdle}"></property>  
    <!-- 获取连接最大等待时间 -->  
    <property name="maxWait" value="${maxWait}"></property>  
</bean>  

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
    <property name="dataSource" ref="dataSource" />  
    <!-- 自动扫描mapping.xml文件 -->  
    <property name="mapperLocations" value="classpath:/mybatis/**/*Mapper.xml"></property>  
</bean>  

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
    <property name="basePackage" value="com.haier.rrs.dao" />  
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
</bean>  

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"  
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />  
</bean> 

我也不知道哪出问题了,网上的都试了,不行图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答