ApplicationContext进行测试的简单使用

news/2024/7/24 4:42:41 标签: 测试, java
第一种:只有一个xml文件
public static void main(String[] args) {
        ApplicationContext ac = null;
        try {
            ac = new ClassPathXmlApplicationContext("beans.xml");
            //ac = new ClassPathXmlApplicationContext("classpath:beans.xml");
        } catch (Exception e) {
            LOGGER.error("spring启动错误", e);
        }


        Account test3 = (autoAccount) ac.getBean("account");
        test3.account();
}

 

 
第二种:有两个以上的文件,并且写出每个文件的名称
public static void main(String[] args) {
    ApplicationContext ac = null;
    try {
        ac = new ClassPathXmlApplicationContext(new String[] {"classpath:beans.xml", "classpath:quartz.xml"});
    } catch (Exception e) {
        LOGGER.error("spring启动错误", e);
    }


    Account test3 = (autoAccount) ac.getBean("account");
    test3.account();

}
 
第三种:通配符
public static void main(String[] args) {
        ApplicationContext ac = null;
        try {
            ac = new ClassPathXmlApplicationContext("classpath:/*.xml");
        } catch (Exception e) {
            LOGGER.error("spring启动错误", e);
        }


        Account test3 = (autoAccount) ac.getBean("account");
        test3.account();
}
 
 
 
 
 

转载于:https://www.cnblogs.com/Alan0218/articles/8472853.html


http://www.niftyadmin.cn/n/1662178.html

相关文章

java中的equals和==的区别

1)对于,如果作用于基本数据类型的变量,则直接比较其存储的 “值”是否相等; 如果作用于引用类型的变量,则比较的是所指向的对象的地址 2)对于equals方法,注意:equals方法不能作用于基…

vue的内置组件transition(转载)

一篇详细的介绍transition 使用详解 ------上边是链接&#xff0c;比较详细 对要使用动画的组件或者模块包上一层transition标签&#xff0c; 1.transition中样式的用法 <transition name"fade"><p v-if"show">hello</p> </transi…

事务的4种隔离级别

数据库事务的隔离级别有4种&#xff0c;由低到高分别为Read uncommitted 、Read committed 、Repeatable read 、Serializable 。而且&#xff0c;在事务的并发操作中可能会出现脏读&#xff0c;不可重复读&#xff0c;幻读。下面通过事例一一阐述它们的概念与联系。 Read unco…

vue中实现图片呢懒加载的过程(vue-lazyload)插件的使用方法)

1.安装插件 npm install vue-lazyload --save-dev 2.在入口文件main.js中引入并使用 import VueLazyload from vue-lazyload 3.main.js中use使用 --或者进行自定义 Vue.use(VueLazyload) main.js 中自定义示例 Vue.use(VueLazyload, {preLoad: 1.3,error: dist/error…

物理读之数据泵备份

SQL ordered by Reads 去磁盘取数据&#xff0c;单位是次&#xff0c;如果太大&#xff0c;IO会导致整个数据库慢&#xff0c;是RAC的环境&#xff0c;可能会导致数据库重启。 BEGIN SYS.KUPW$WORKER.MAIN(SYS_EXPORT_SCHEMA_01, SYS, 0); END; ##代表数据泵备份&#xff0c;不…

git操作详解(转载)

转载被人链接&#xff0c;看到的一篇比较详尽清晰的文章 上边是链接&#xff0c;点击进入

WebStorm ES6 语法支持设置

WebStorm ES6 语法支持设置 https://www.jianshu.com/p/b4390919a5b5 ide也会出现提示&#xff0c;选择接收就可以了&#xff1b;

常见的一些前端知识点总结

1&#xff0c;如何实现vue的路由填坑记录懒加载&#xff0c;有几种写法 在vue中组件懒加载又称为代码分割&#xff0c;也叫延迟加载&#xff0c;即在需要的时候进行加载&#xff0c;随用随载。 不用懒加载的话&#xff0c;webpack打包后的文件会异常过大&#xff0c;造成进入首…