1+ package com .devicehive .application ;
2+
3+ /*
4+ * #%L
5+ * DeviceHive Frontend Logic
6+ * %%
7+ * Copyright (C) 2016 DataArt
8+ * %%
9+ * Licensed under the Apache License, Version 2.0 (the "License");
10+ * you may not use this file except in compliance with the License.
11+ * You may obtain a copy of the License at
12+ *
13+ * http://www.apache.org/licenses/LICENSE-2.0
14+ *
15+ * Unless required by applicable law or agreed to in writing, software
16+ * distributed under the License is distributed on an "AS IS" BASIS,
17+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+ * See the License for the specific language governing permissions and
19+ * limitations under the License.
20+ * #L%
21+ */
22+
23+ import org .springframework .context .event .ContextRefreshedEvent ;
24+ import org .springframework .context .event .EventListener ;
25+ import org .springframework .core .env .ConfigurableEnvironment ;
26+ import org .springframework .core .env .MapPropertySource ;
27+ import org .springframework .stereotype .Component ;
28+
29+ import java .util .ArrayList ;
30+ import java .util .List ;
31+ import java .util .Collection ;
32+
33+ @ Component
34+ public class AppContextEventListener {
35+
36+ @ EventListener
37+ public void handleContextRefreshed (ContextRefreshedEvent event ) {
38+ printActiveProperties ((ConfigurableEnvironment ) event .getApplicationContext ().getEnvironment ());
39+ }
40+
41+ private void printActiveProperties (ConfigurableEnvironment env ) {
42+
43+ System .out .println ("************************* ACTIVE APP PROPERTIES ******************************" );
44+
45+ List <MapPropertySource > propertySources = new ArrayList <>();
46+
47+ env .getPropertySources ().forEach (it -> {
48+ if (it instanceof MapPropertySource ) {
49+ propertySources .add ((MapPropertySource ) it );
50+ }
51+ });
52+
53+ propertySources .stream ()
54+ .map (propertySource -> propertySource .getSource ().keySet ())
55+ .flatMap (Collection ::stream )
56+ .distinct ()
57+ .sorted ()
58+ .forEach (key -> {
59+ try {
60+ System .out .println (key + "=" + env .getProperty (key ));
61+ } catch (Exception e ) {
62+ System .out .println (e );
63+ }
64+ });
65+ System .out .println ("******************************************************************************" );
66+ }
67+ }
0 commit comments