Quote:
Originally Posted by waitingduck
Hi,
I have a problem with the example in ch2, using java-base configuration. Most of the code doing well. However, in the main class, there is a annotationConfigApplicationContext class which is not define before. What should I do with it?
Thanks.
|
Do you mean following example? If yes, AnnotationConfigApplicationContext class is already imported, and is used to create a Spring ApplicationContext instance. I couldn't figure out what is the exact problem you faced here. Could you provide a little bit more information about it?
package com.wiley.beginningspring.ch2;
import org.springframework.context.annotation.AnnotationC onfigApplicationContext;
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(Ch2BeanConfigur ation.class);
AccountService accountService = applicationContext.getBean("accountService", AccountService.class);
System.out.println("Before money transfer");
System.out.println("Account 1 balance :" + accountService.getAccount(1).getBalance());
System.out.println("Account 2 balance :" + accountService.getAccount(2).getBalance());
accountService.transferMoney(1, 2, 5.0);
System.out.println("After money transfer");
System.out.println("Account 1 balance :" + accountService.getAccount(1).getBalance());
System.out.println("Account 2 balance :" + accountService.getAccount(2).getBalance());
}
}