Skip to content

Commit bae0f1d

Browse files
committed
1 parent f250fd5 commit bae0f1d

File tree

10 files changed

+105
-0
lines changed

10 files changed

+105
-0
lines changed

spring-core-events/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-framework-tutorial-parent</artifactId>
7+
<groupId>com.jstobigdata</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>spring-core-events</artifactId>
13+
14+
15+
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events;
2+
3+
public class AnnEventListener {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events;
2+
3+
public class AppConfig {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events;
2+
3+
public class EventListener {
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.jsbd.events.synchronous;
2+
3+
import com.jsbd.events.UserEvent;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.ApplicationEventPublisher;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class EventPublisher {
10+
11+
@Autowired //use setter based injection
12+
private ApplicationEventPublisher applicationEventPublisher;
13+
14+
public void publishEvent(String message, Integer eventId) {
15+
applicationEventPublisher.publishEvent(
16+
new UserEvent(this, message, eventId )
17+
);
18+
}
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.jsbd.events;
2+
3+
import org.springframework.context.ApplicationEvent;
4+
5+
import java.util.StringJoiner;
6+
7+
public class CustomAppEvent extends ApplicationEvent {
8+
9+
//Custom property
10+
private String message;
11+
12+
/**
13+
* Create a new {@code ApplicationEvent}.
14+
* @param source the object on which the event initially occurred or with
15+
* which the event is associated (never {@code null})
16+
*/
17+
public CustomAppEvent(Object source) {
18+
super(source);
19+
}
20+
21+
/**
22+
* Constructor to set the properties.
23+
* @param source
24+
* @param message
25+
*/
26+
public CustomAppEvent(Object source, String message) {
27+
super(source);
28+
this.message = message;
29+
}
30+
31+
public String getMessage() {
32+
return message;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
return new StringJoiner(", ", CustomAppEvent.class.getSimpleName() + "[", "]")
38+
.add("message='" + message + "'")
39+
.add("source=" + source)
40+
.toString();
41+
}
42+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events.generic;
2+
3+
public class GenericEventListener {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events.generic;
2+
3+
public class Person {
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import static org.junit.jupiter.api.Assertions.*;
2+
3+
class EventPublisherTest {
4+
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.jsbd.events.synchronous;
2+
3+
public class GenericEventTest {
4+
}

0 commit comments

Comments
 (0)