blob: 14c2599d02f510e75dbee962edec631ae1b92b54 (
plain)
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
|
package com.example.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = "com.example.spring")
public class App {
public static void main(String[] args) {
@SuppressWarnings("resource")
ApplicationContext ctx =
new AnnotationConfigApplicationContext(App.class);
MathsUser mathsUser = ctx.getBean(MathsUser.class);
mathsUser.doTask();
}
// Another way
public static void main2(String[] args) {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext ctx =
new AnnotationConfigApplicationContext();
ctx.scan("com.example.spring");
ctx.refresh();
MathsUser mathsUser = ctx.getBean(MathsUser.class);
mathsUser.doTask();
}
}
|