-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...spring/src/main/java/com/leone/boot/spring/bootstrap/SpringApplicationEventBootstrap.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,25 @@ | ||
package com.leone.boot.spring.bootstrap; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
public class SpringApplicationEventBootstrap { | ||
public static void main(String[] args) { | ||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); | ||
|
||
context.addApplicationListener(event -> { | ||
System.err.println("监听到事件" + event); | ||
}); | ||
context.refresh(); | ||
|
||
context.publishEvent("hello world"); | ||
|
||
context.close(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...pring/src/main/java/com/leone/boot/spring/context/FirstApplicationContextInitializer.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,24 @@ | ||
package com.leone.boot.spring.context; | ||
|
||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
@Order(value = Ordered.HIGHEST_PRECEDENCE) | ||
public class FirstApplicationContextInitializer<C extends ConfigurableApplicationContext> | ||
implements ApplicationContextInitializer<C> { | ||
|
||
@Override | ||
public void initialize(C application) { | ||
System.out.println("first Application initialize " + application.getId()); | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ring/src/main/java/com/leone/boot/spring/context/SecondApplicationContextInitializer.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,25 @@ | ||
package com.leone.boot.spring.context; | ||
|
||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
public class SecondApplicationContextInitializer implements ApplicationContextInitializer, Ordered { | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) { | ||
System.out.println("second application initialize " + configurableApplicationContext.getId()); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Ordered.LOWEST_PRECEDENCE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ring/src/main/java/com/leone/boot/spring/listener/AfterHelloWorldApplicationListener.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,24 @@ | ||
package com.leone.boot.spring.listener; | ||
|
||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
public class AfterHelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent>, Ordered { | ||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
System.out.println("after hello world listener " + event.getApplicationContext().getId() + " timestamp: " + event.getTimestamp()); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Ordered.LOWEST_PRECEDENCE; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ot-spring/src/main/java/com/leone/boot/spring/listener/HelloWorldApplicationListener.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,20 @@ | ||
package com.leone.boot.spring.listener; | ||
|
||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
public class HelloWorldApplicationListener implements ApplicationListener<ContextRefreshedEvent> { | ||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
System.out.println("hello world listener " + event.getApplicationContext().getId() + " timestamp: " + event.getTimestamp()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
spring-boot-spring/src/main/java/com/leone/boot/spring/run/HelloWorldRunListener.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,48 @@ | ||
package com.leone.boot.spring.run; | ||
|
||
import org.springframework.boot.SpringApplicationRunListener; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
|
||
/** | ||
* <p> | ||
* | ||
* @author leone | ||
* @since 2019-05-26 | ||
**/ | ||
public class HelloWorldRunListener implements SpringApplicationRunListener { | ||
@Override | ||
public void starting() { | ||
System.out.println("starting..."); | ||
} | ||
|
||
@Override | ||
public void environmentPrepared(ConfigurableEnvironment environment) { | ||
|
||
} | ||
|
||
@Override | ||
public void contextPrepared(ConfigurableApplicationContext context) { | ||
|
||
} | ||
|
||
@Override | ||
public void contextLoaded(ConfigurableApplicationContext context) { | ||
|
||
} | ||
|
||
@Override | ||
public void started(ConfigurableApplicationContext context) { | ||
|
||
} | ||
|
||
@Override | ||
public void running(ConfigurableApplicationContext context) { | ||
|
||
} | ||
|
||
@Override | ||
public void failed(ConfigurableApplicationContext context, Throwable exception) { | ||
|
||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
spring-boot-spring/src/main/resources/META-INF/spring.factories
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 |
---|---|---|
@@ -1,2 +1,13 @@ | ||
org.springframework.context.ApplicationContextInitializer=\ | ||
apple | ||
com.leone.boot.spring.context.SecondApplicationContextInitializer,\ | ||
com.leone.boot.spring.context.FirstApplicationContextInitializer | ||
|
||
org.springframework.context.ApplicationListener=\ | ||
com.leone.boot.spring.listener.AfterHelloWorldApplicationListener,\ | ||
com.leone.boot.spring.listener.HelloWorldApplicationListener | ||
|
||
|
||
|
||
|
||
org.springframework.context.SpringApplicationRunListener=\ | ||
com.leone.boot.spring.run.HelloWorldRunListener |