-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpringDemoMain.txt
96 lines (69 loc) · 2.22 KB
/
SpringDemoMain.txt
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Maven project ->
qucik start archetype
jdk 8
Spring jar are downloaded by adding the below dependency:
----------------------------------
pom.xml-> project object model
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
File -> save jar is downloaded (if internet is live)-> Maven lib
-----------------------------------------
package com.niit.SpringDemoMain;
public interface HelloWorld {
public String sayHello();
}
-------------------------------------
package config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.niit.SpringDemoMain.*;
@Configuration
@ComponentScan(basePackages="com.niit")
public class AppConfig {
@Bean(name="helloworld")
public HelloWorld getHelloworld()
{
return new HelloWorld() {
public String sayHello() {
// TODO Auto-generated method stub
return "welcome to spring";
}
};
}
}
----------------------------------------------
package com.niit.SpringDemoMain;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import config.AppConfig;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
AbstractApplicationContext ctx=new
AnnotationConfigApplicationContext(AppConfig.class);
HelloWorld h= (HelloWorld)ctx.getBean("hello");
System.out.println(h.sayHello());
}
}
-------------------------------------