1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package com.example.fp;
import java.util.List;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class FinancialPlannerApp {
/**
* @param args
*/
public static void main(String[] args) {
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:META-INF/spring/applicationContext.xml"});
// Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.
// Delegates to doClose() for the actual closing procedure.
// This will trigger the destroy-method of the DataSource in our application (for example, in case of unexpected JVM shutdown).
ctx.registerShutdownHook();
UserManager userManager = ctx.getBean("userManager", UserManager.class);
// Create an account
System.out.println("Creating users...");
userManager.create(new User("Kamal", "Kamal Wickramanayake", "abc123", true));
userManager.create(new User("Rajith", "Rajith Virajana", "abc123", true));
userManager.create(new User("Uththama", "Uththama Yapa", "abc123", true));
List<User> users = userManager.findAll();
for (User user : users) {
System.out.println(user);
}
User newUser = new User("Kamal2", "Kamal Wickramanayake", "abc123", true);
System.out.println(newUser);
userManager.create(newUser);
System.out.println(newUser);
ctx.close();
}
}
|