Skip to content

Commit fca853a

Browse files
author
Aleksandar Osenov
committed
Little fix for listener
1 parent 05b8342 commit fca853a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

devicehive-auth/src/main/java/com/devicehive/application/AppContextEventListener.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
* #L%
2121
*/
2222

23-
import org.springframework.context.event.ContextRefreshedEvent;
24-
import org.springframework.context.event.EventListener;
23+
import org.springframework.boot.context.event.ApplicationPreparedEvent;
24+
import org.springframework.boot.context.event.SpringApplicationEvent;
25+
import org.springframework.context.ApplicationEvent;
26+
import org.springframework.context.ApplicationListener;
27+
import org.springframework.context.event.ApplicationContextEvent;
2528
import org.springframework.core.env.ConfigurableEnvironment;
2629
import org.springframework.core.env.MapPropertySource;
27-
import org.springframework.stereotype.Component;
2830

2931
import java.util.ArrayList;
30-
import java.util.List;
3132
import java.util.Collection;
33+
import java.util.List;
3234

33-
@Component
34-
public class AppContextEventListener {
35-
36-
@EventListener
37-
public void handleContextRefreshed(ContextRefreshedEvent event) {
38-
printActiveProperties((ConfigurableEnvironment) event.getApplicationContext().getEnvironment());
39-
}
35+
public class AppContextEventListener implements ApplicationListener<ApplicationEvent> {
4036

4137
private void printActiveProperties(ConfigurableEnvironment env) {
4238

@@ -64,4 +60,11 @@ private void printActiveProperties(ConfigurableEnvironment env) {
6460
});
6561
System.out.println("******************************************************************************");
6662
}
63+
64+
@Override
65+
public void onApplicationEvent(ApplicationEvent event) {
66+
if(event instanceof ApplicationPreparedEvent) {
67+
printActiveProperties((ConfigurableEnvironment) ((ApplicationPreparedEvent) event).getApplicationContext().getEnvironment());
68+
}
69+
}
6770
}

devicehive-auth/src/main/java/com/devicehive/application/DeviceHiveAuthApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class DeviceHiveAuthApplication extends SpringBootServletInitializer {
5757

5858
public static void main(String... args) {
5959
ConfigurableApplicationContext context = new SpringApplicationBuilder()
60+
.listeners(new AppContextEventListener())
6061
.sources(DeviceHiveAuthApplication.class)
6162
.web(WebApplicationType.SERVLET)
6263
.run(args);

0 commit comments

Comments
 (0)