66import org .springframework .context .ApplicationListener ;
77import org .springframework .context .event .ContextRefreshedEvent ;
88import org .springframework .stereotype .Component ;
9- import org .woehlke .learn .learnneo4j .configuration .properties .MyAppProperties ;
10- import org .woehlke .learn .learnneo4j .configuration .properties .OtherAppProperties ;
11- import org .woehlke .learn .learnneo4j .configuration .properties .SpringAppProperties ;
9+ import org .woehlke .learn .learnneo4j .configuration .properties .*;
1210import org .woehlke .learn .learnneo4j .model .graph .Category ;
1311import org .woehlke .learn .learnneo4j .model .graph .category .CategoryRepository ;
12+ import org .woehlke .learn .learnneo4j .model .graph .category .CategoryService ;
13+ import org .woehlke .learn .learnneo4j .model .orm .portinfo .PortinfoService ;
1414
1515@ Component
1616public class StartupListener implements ApplicationListener <ContextRefreshedEvent > {
@@ -19,46 +19,72 @@ public class StartupListener implements ApplicationListener<ContextRefreshedEven
1919
2020 private final CategoryRepository categoryRepository ;
2121
22- private final MyAppProperties myAppProperties ;
22+ private final CategoryService categoryService ;
2323
24- private final OtherAppProperties otherAppProperties ;
24+ private final PortinfoService portinfoService ;
2525
26- private final SpringAppProperties springAppProperties ;
26+ private final MyApplicationProperties myApplicationProperties ;
27+
28+ private final MyHibernateProperties myHibernateProperties ;
29+
30+ private final MyInfoProperties myInfoProperties ;
31+
32+ private final MyManagementProperties myManagementProperties ;
33+
34+ private final MyServerProperties myServerProperties ;
35+
36+ private final MySpringBootProperties mySpringBootProperties ;
2737
2838 @ Autowired
29- public StartupListener (CategoryRepository categoryRepository , MyAppProperties myAppProperties , OtherAppProperties otherAppProperties , SpringAppProperties springAppProperties ) {
39+ public StartupListener (CategoryRepository categoryRepository , CategoryService categoryService , PortinfoService portinfoService , MyApplicationProperties myApplicationProperties , MyHibernateProperties myHibernateProperties , MyInfoProperties myInfoProperties , MyManagementProperties myManagementProperties , MyServerProperties myServerProperties , MySpringBootProperties mySpringBootProperties ) {
3040 this .categoryRepository = categoryRepository ;
31- this .myAppProperties = myAppProperties ;
32- this .otherAppProperties = otherAppProperties ;
33- this .springAppProperties = springAppProperties ;
41+ this .categoryService = categoryService ;
42+ this .portinfoService = portinfoService ;
43+ this .myApplicationProperties = myApplicationProperties ;
44+ this .myHibernateProperties = myHibernateProperties ;
45+ this .myInfoProperties = myInfoProperties ;
46+ this .myManagementProperties = myManagementProperties ;
47+ this .myServerProperties = myServerProperties ;
48+ this .mySpringBootProperties = mySpringBootProperties ;
3449 }
3550
3651 @ Override
3752 public void onApplicationEvent (ContextRefreshedEvent event ) {
38- log .info (" =========================== " );
39- log .info (" === Application Started === " );
40- log .info (" =========================== " );
41- this .categoryRepository .deleteAll ();
42- this .categoryRepository .save (new Category ("www" ));
43- this .categoryRepository .save (new Category ("qt4" ));
44- this .categoryRepository .save (new Category ("qt5" ));
45- // fetch all Categories
46- log .info ("Categories found with findAll():" );
47- log .info ("--------------------------------" );
48- for (Category category : this .categoryRepository .findAll ()) {
49- log .info (category .toString ());
53+ log .info (" ================================ " );
54+ log .info (" ===== Application Started ====== " );
55+ log .info (" ================================ " );
56+ if ( this .myApplicationProperties .getCreateTestDataAtStartup ()){
57+ this .categoryRepository .deleteAll ();
58+ this .categoryRepository .save (new Category ("www" ));
59+ this .categoryRepository .save (new Category ("qt4" ));
60+ this .categoryRepository .save (new Category ("qt5" ));
61+ // fetch all Categories
62+ log .info (" Categories found with findAll(): " );
63+ log .info (" -------------------------------- " );
64+ for (Category category : this .categoryService .findAll ()) {
65+ log .info (" category : " +category .toString ());
66+ }
67+ log .info (" -------------------------------- " );
68+ log .info (" fetch an individual Category: " );
69+ log .info (" findByCategory('www'): " );
70+ log .info (" -------------------------------- " );
71+ log .info (this .categoryService .findByName ("www" ).toString ());
72+ log .info (" ================================ " );
5073 }
51- System .out .println ();
52- log .info ("fetch an individual Category: " );
53- log .info ("Category found with findByCategory('www'):" );
54- log .info ("--------------------------------" );
55- log .info (this .categoryRepository .findByName ("www" ).toString ());
56- log .info ("--------------------------------" );
57- log .info (myAppProperties .toString ());
58- log .info ("--------------------------------" );
59- log .info (otherAppProperties .toString ());
60- log .info ("--------------------------------" );
61- log .info (springAppProperties .toString ());
62- log .info ("--------------------------------" );
74+ log .info (" -------------------------------- " );
75+ log .info (" Properties " );
76+ log .info (" -------------------------------- " );
77+ log .info (this .myApplicationProperties .toString ());
78+ log .info (" -------------------------------- " );
79+ log .info (this .myInfoProperties .toString ());
80+ log .info (" -------------------------------- " );
81+ log .info (this .myManagementProperties .toString ());
82+ log .info (" -------------------------------- " );
83+ log .info (this .myServerProperties .toString ());
84+ log .info (" -------------------------------- " );
85+ log .info (this .myHibernateProperties .toString ());
86+ log .info (" -------------------------------- " );
87+ log .info (this .mySpringBootProperties .toString ());
88+ log .info (" -------------------------------- " );
6389 }
6490}
0 commit comments