AnnotationConfigApplicationContext的register方法
来源:互联网 发布:mac里的照片和相簿 编辑:程序博客网 时间:2024/05/21 22:30
public class Main {public static void main(String[] args) {AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();applicationContext.register(Ch2BeanConfiguration.class);// applicationContext.scan("com.mlf");// # must user refress() methodapplicationContext.refresh();AccountService accountService = (AccountService) applicationContext.getBean("accountService");System.out.println("Beafore money transfer");System.out.println("Account1 balance:" + accountService.getAccount(1l).getBalance());System.out.println("Account2 balance:" + accountService.getAccount(2l).getBalance());System.out.println("------------------------------------");accountService.transferMoney(1l, 2l, 5.5);System.out.println("After money transfer");System.out.println("Account1 balance:" + accountService.getAccount(1l).getBalance());System.out.println("Account2 balance:" + accountService.getAccount(2l).getBalance());System.out.println("------------------------------------");}}
package com.mlf.spring;import org.springframework.context.annotation.Bean;import org.springframework.stereotype.Component;import com.mlf.spring.dao.AccountDao;import com.mlf.spring.dao.impl.AccountDaoInMemoryImpl;import com.mlf.spring.service.AccountService;import com.mlf.spring.service.impl.AccountServiceImpl;@Componentpublic class Ch2BeanConfiguration {@Beanpublic AccountService accountService() {AccountServiceImpl bean = new AccountServiceImpl();bean.setAccountDao(accountDao());return bean;}@Beanpublic AccountDao accountDao() {AccountDaoInMemoryImpl beAccountDaoInMemoryImpl = new AccountDaoInMemoryImpl();return beAccountDaoInMemoryImpl;}}
阅读全文
0 0
- AnnotationConfigApplicationContext的register方法
- Applet的register方法
- spring注解开发AnnotationConfigApplicationContext的使用
- spring注解开发AnnotationConfigApplicationContext的使用
- spring注解开发AnnotationConfigApplicationContext的使用
- Selector select方法阻塞register的解决方法
- 学习使用register定义变量的方法
- 学习使用register定义变量的方法。
- coding遇到的疑难点--AnnotationConfigApplicationContext 使用出错
- Register 方法学习笔记
- 【程序45】学习使用register定义变量的方法
- 使得register/login居中的方法_android:gravity="center"
- Register 属性的设置
- ConvertUtils.register的作用!
- ConvertUtils.register的作用
- C语言的register
- ConvertUtils.register的作用!
- register关键字的作用
- Java DeadLock
- java中的四种线程池
- spring切面切点@Aspect的使用
- python基础(五)——CGI编程
- plsql存储过程以及在java中调用
- AnnotationConfigApplicationContext的register方法
- Js实现页面跳转的几种方式
- linux结构详解
- Android内存泄漏之前因后果
- jquery二级联动下拉菜单
- 花生壳+IIS部署外网项目
- 面试题4:替换空格
- HTTP、FTP状态码 汇总
- iOS-手把手教你如何写block