Spring中用ApplicationContext进行测试的简单使用
来源:互联网 发布:bmob后端云 java 编辑:程序博客网 时间:2024/06/06 01:26
分为三种情况:
第一种:只有一个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(); }
0 0
- Spring中用ApplicationContext进行测试的简单使用
- Spring的简单使用BeanFactory和ApplicationContext
- Spring中ClassPathXmlApplicationContext和ApplicationContext 的简单使用
- ApplicationContext 的使用时机 - [Spring]
- 简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例
- Spring中使用ApplicationContext进行事件的监听之ApplicationEvent,ApplicationListener
- 使用 CasperJS 进行简单的 UI 测试
- spring中ApplicationContext的获取与使用
- java spring配置文件applicationcontext.xml的使用
- Spring -- ApplicationContext使用及Bean的配置
- Spring -- ApplicationContext使用及Bean的配置
- 使用Spring的测试机制进行集成测试
- 用JUnit测试Spring中的配置,需要使用ApplicationContext
- spring ApplicationContext 使用总结
- spring中使用ApplicationContext
- 使用junit进行Spring测试
- 获取spring中的ApplicationContext最简单的方式
- 使用spring提供的测试功能结合JUnit4进行单元测试
- Java堆.栈和常量池学习
- 形参和实参的区别
- [Unity小技巧] 避免手机触屏连续多次触发触摸touch事件
- CSS总结2
- 机器学习中的归一化
- Spring中用ApplicationContext进行测试的简单使用
- CSS总结3
- [翻译] We have a problem with promises
- CSS总结4
- javascript总结1
- javascript总结2
- 计算器 案例
- Leetcode 419 Battleships in a Board
- javascript总结3