forked from dyc87112/SpringBoot-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent
- Loading branch information
Showing
11 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.didispace</groupId> | ||
<artifactId>Chapter1-2-1</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Chapter1-2-1</name> | ||
<description>Spring Boot 2.0 features : Application Events and Listeners</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.0.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@Slf4j | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
@Bean | ||
public DataLoader dataLoader() { | ||
return new DataLoader(); | ||
} | ||
|
||
@Slf4j | ||
static class DataLoader implements CommandLineRunner { | ||
|
||
@Override | ||
public void run(String... strings) throws Exception { | ||
log.info("Loading data..."); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Chapter1-2-1/src/main/java/com/didispace/ApplicationEnvironmentPreparedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationEnvironmentPreparedEventListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { | ||
log.info("......ApplicationEnvironmentPreparedEvent......"); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Chapter1-2-1/src/main/java/com/didispace/ApplicationFailedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationFailedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationFailedEventListener implements ApplicationListener<ApplicationFailedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationFailedEvent event) { | ||
log.info("......ApplicationFailedEvent......"); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Chapter1-2-1/src/main/java/com/didispace/ApplicationPreparedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationPreparedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationPreparedEventListener implements ApplicationListener<ApplicationPreparedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationPreparedEvent event) { | ||
log.info("......ApplicationPreparedEvent......"); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Chapter1-2-1/src/main/java/com/didispace/ApplicationReadyEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationReadyEvent event) { | ||
log.info("......ApplicationReadyEvent......"); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
Chapter1-2-1/src/main/java/com/didispace/ApplicationStartedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.context.event.ApplicationStartedEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationStartedEvent event) { | ||
log.info("......ApplicationStartedEvent......"); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Chapter1-2-1/src/main/java/com/didispace/ApplicationStartingEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.didispace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.context.event.ApplicationStartingEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
@Slf4j | ||
public class ApplicationStartingEventListener implements ApplicationListener<ApplicationStartingEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationStartingEvent event) { | ||
log.info("......ApplicationStartingEvent......"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
org.springframework.context.ApplicationListener=com.didispace.ApplicationEnvironmentPreparedEventListener,\ | ||
com.didispace.ApplicationFailedEventListener,\ | ||
com.didispace.ApplicationPreparedEventListener,\ | ||
com.didispace.ApplicationReadyEventListener,\ | ||
com.didispace.ApplicationStartedEventListener,\ | ||
com.didispace.ApplicationStartingEventListener |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters