zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    xcode中的udp接收数据
    FMX.MEDIA中的录音功能实现
    DELPHI XE功能
    xcode 中运用lame进行caf文件到mp3文件的转换
    xcode中用AVAudioRecorder录音到指定的caf文件
    enum 在c中的使用(枚举类型)
    c语言中typedef的几种用法
    pta 两个有序链表序列的交集
    Level-order Traversal(c语言函数指针样例)
    求二叉树高度
  • 原文地址:https://www.cnblogs.com/libin6505/p/10573709.html
Copyright © 2011-2022 走看看