File tree 3 files changed +73
-0
lines changed
SpringTutorials/src/spring_JSR_250_annotations
3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+
3
+ <beans xmlns =" http://www.springframework.org/schema/beans"
4
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
5
+ xmlns : context =" http://www.springframework.org/schema/context"
6
+ xsi : schemaLocation =" http://www.springframework.org/schema/beans
7
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
8
+ http://www.springframework.org/schema/context
9
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd" >
10
+
11
+ <context : annotation-config />
12
+
13
+ <bean id =" helloWorld"
14
+ class =" spring_JSR_250_annotations.HelloWorld"
15
+ init-method =" init" destroy-method =" destroy" >
16
+ <property name =" message" value =" Hello World from 2015/07/30!" />
17
+ </bean >
18
+
19
+ </beans >
Original file line number Diff line number Diff line change
1
+ package spring_JSR_250_annotations ;
2
+
3
+ import javax .annotation .PostConstruct ;
4
+ import javax .annotation .PreDestroy ;
5
+
6
+ import lombok .Getter ;
7
+ import lombok .Setter ;
8
+
9
+ public class HelloWorld {
10
+ @ Setter @ Getter
11
+ private String message ;
12
+
13
+ // public void setMessage(String message) {
14
+ // this.message = message;
15
+ // }
16
+ //
17
+ // public String getMessage() {
18
+ // System.out.println("Your Message : " + message);
19
+ // return message;
20
+ // }
21
+
22
+ @ PostConstruct
23
+ public void init () {
24
+ System .out .println ("Bean is going through init." );
25
+ }
26
+
27
+ @ PreDestroy
28
+ public void destroy () {
29
+ System .out .println ("Bean will destroy now." );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ package spring_JSR_250_annotations ;
2
+
3
+ /**Following is the content of the MainApp.java file. Here you
4
+ * need to register a shutdown hook registerShutdownHook() method that
5
+ * is declared on the AbstractApplicationContext class.
6
+ * This will ensures a graceful shutdown and calls the relevant destroy methods.*/
7
+
8
+ import org .springframework .context .support .AbstractApplicationContext ;
9
+ import org .springframework .context .support .ClassPathXmlApplicationContext ;
10
+
11
+ public class MainApp {
12
+ public static void main (String [] args ) {
13
+
14
+ AbstractApplicationContext context = new ClassPathXmlApplicationContext (
15
+ "spring_JSR_250_annotations/Beans.xml" );
16
+
17
+ HelloWorld obj = (HelloWorld ) context .getBean ("helloWorld" );
18
+ obj .getMessage ();
19
+ context .registerShutdownHook ();
20
+
21
+ System .out .print ("\n The end!\n " );
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments