Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4978f0c

Browse files
Spring JSR-250 annotations
1 parent247cf18 commit4978f0c

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beansxmlns="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+
<beanid="helloWorld"
14+
class="spring_JSR_250_annotations.HelloWorld"
15+
init-method="init"destroy-method="destroy">
16+
<propertyname="message"value="Hello World from 2015/07/30!"/>
17+
</bean>
18+
19+
</beans>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagespring_JSR_250_annotations;
2+
3+
importjavax.annotation.PostConstruct;
4+
importjavax.annotation.PreDestroy;
5+
6+
importlombok.Getter;
7+
importlombok.Setter;
8+
9+
publicclassHelloWorld {
10+
@Setter@Getter
11+
privateStringmessage;
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+
publicvoidinit() {
24+
System.out.println("Bean is going through init.");
25+
}
26+
27+
@PreDestroy
28+
publicvoiddestroy() {
29+
System.out.println("Bean will destroy now.");
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packagespring_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+
importorg.springframework.context.support.AbstractApplicationContext;
9+
importorg.springframework.context.support.ClassPathXmlApplicationContext;
10+
11+
publicclassMainApp {
12+
publicstaticvoidmain(String[]args) {
13+
14+
AbstractApplicationContextcontext =newClassPathXmlApplicationContext(
15+
"spring_JSR_250_annotations/Beans.xml");
16+
17+
HelloWorldobj = (HelloWorld)context.getBean("helloWorld");
18+
obj.getMessage();
19+
context.registerShutdownHook();
20+
21+
System.out.print("\nThe end!\n");
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp