我想从POJO Class

时间:2017-01-14 09:23:09

标签: spring javabeans pojo

  1. servlet-context.xml(部分)

    <context:annotation-config />
    
    <context:component-scan base-package="com.eai.scard">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    
    <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    
    </context:component-scan>
    
  2. 目标Pojo类(我想将其转换为Spring-bean类)

    package com.eai.scard.mdm;
    
    import java.io.UnsupportedEncodingException;
    
    import javax.annotation.Resource;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Component;
    
    other import ...~
    
    @Component
    
    public class EmsRcv implements EMSListener {
    
        private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
    
        @Resource(name="admstService")
        AdmstService admstService;
    }
    
  3. 服务类

    package com.eai.scard.service;
    
    import javax.annotation.Resource;
    
    import org.springframework.stereotype.Service;
    
    import com.eai.scard.dao.AdmstDao;
    import com.eai.scard.model.Department;
    import com.eai.scard.model.Employee;
    
    @Service
    public class AdmstService {
    
        @Resource(name="admstDao")
        AdmstDao admstDao;
    
        public int insertDept(Department dept) {
            return admstDao.insertDept(dept);
        }
    
        public int insertEmp(Employee emp) {
            return admstDao.insertEmp(emp);
        }
    }
    
  4. DAO课程

    package com.eai.scard.dao;
    
    import org.mybatis.spring.support.SqlSessionDaoSupport;
    import org.springframework.stereotype.Repository;
    
    import com.eai.scard.model.Department;
    import com.eai.scard.model.Employee;
    
    @Repository
    public class AdmstDao extends SqlSessionDaoSupport {
    
        public int insertDept(Department dept) {
            return getSqlSession().insert("admst.insertDept", dept);
        }
    
        public int insertEmp(Employee emp) {
            return getSqlSession().insert("admst.insertEmp", emp);
        }
    
    }
    
  5. 我想让Spring Bean Class使用@Autowired(或@Resource)注释。但在上面的代码中,'admstService'null。我该怎么做以及为什么会这样?

0 个答案:

没有答案