• spring环境测试


    比如有个service类:(再建个接口类)

    package com.tydic.jtcrm.batch.service.impl;
    
    import java.util.Map;
    
    import javax.annotation.Resource;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Service;
    
    import com.tydic.jtcrm.batch.service.BatchRealNameService;
    import com.tydic.jtcrm.common.service.ParentService;
    
    
    @Service
    public class BatchRealNameServiceImpl extends ParentService implements  BatchRealNameService{
        
        private final static Logger logger = LoggerFactory.getLogger(BatchRealNameServiceImpl.class);
    
        //根据待处理文件id 查询对应数据记录数量
        @Override
        public Map queryOneByHandleStatus(String handleStatus){
            Map provMap = this.selectOne("ds1", "batchReal.queryOneByHandleStatus",handleStatus);
            return provMap;
        }
        
    }

    【需要注意的是:要加@service注解】

    然后在其他随便一个类里写个main方法即可测试:

    public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-config/disconf.beans.xml"); 
            BatchRealNameService service = (BatchRealNameService)context.getBean("batchRealNameServiceImpl");
            Map map = service.queryOneByHandleStatus("1100");
            System.out.println(map);
        }

    这里需要注意的是:

    1、ApplicationContext  对象创建时后面参数要写 spring 配置文件的路径。

    2、getBean后面的参数要写对应类的首字母小写。 即实际类是 BatchRealNameServiceImpl  而加载bean时,要写成   batchRealNameServiceImpl

  • 相关阅读:
    每个Java开发人员都应该知道的4个Spring注解
    JVM中的动态语言支持简介
    深入探索Java设计模式(五)之构建器模式
    Java——MVC模式
    程序出了问题,报错只能参考
    查看电脑端口占用情况
    Java——参数传递
    Python——关于定义过程
    Java——super的使用
    关于如何查看论文是否被SCI或者EI收录
  • 原文地址:https://www.cnblogs.com/libin6505/p/10573709.html
Copyright © 2020-2023  润新知