java - ContextRefreshedEvent is not triggring on AnnotationConfigApplicationContext loading -


i created spring application , i'm loading application context in standalone java application. code following

public class application {     public static void main(string[] args) {         applicationcontext applicationcontext = new annotationconfigapplicationcontext(config.class);     } } 

i want copy data in in-memory database before application start. if put code after applicationcontext applicationcontext = new annotationconfigapplicationcontext(config.class); starts copying data after context initialize. application start processing orders before copy data in in-memory database. want copy data before application start , after beans initialize(context load).

i tried following

public class apppostloader implements applicationlistener<contextrefreshedevent> {      public void onapplicationevent(contextrefreshedevent event) {         redistemplate<string, string> redistemplate = (redistemplate) event.getapplicationcontext().getbean("redistemplate");         //coping data     } } 

but it's not calling onapplicationevent method.

how can call before application start , after context load.

add @component on listener class


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -