2

I have an application that is composed of more than 100 spring.xml files. I would like to figure out the amount of time taken for loading all the beans defined in these spring.xml files. Please can you let me know how this can be done? Thank You!

A0__oN
  • 8,740
  • 6
  • 40
  • 61
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • http://stackoverflow.com/questions/8686507/how-to-add-a-hook-to-the-application-context-initialization-event maybe –  May 17 '16 at 04:43

2 Answers2

1

You can calculate spring beans loading time using test class. Load all your xml files manually (without using annotation - @ContextConfiguration).

@Before
public void setup(){
    long then = System.currentTimeMillis();
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "com/abc/applicationContext.xml",
            "com/abc/service-context.xml");
    long now = System.currentTimeMillis();
    System.out.println("Difference is :"+(now - then));
}
asg
  • 2,248
  • 3
  • 18
  • 26
0

long then = System.currentTimeMillis();

// do all your stuff

System.out.println("Milliseconds taken: " + System.currentTimeMillis() - then);

  • @PunterVicky wherever you want to being timing things, it isn't that complicated. You're just marking a starting point, then subtracting it from the current time. – 2ARSJcdocuyVu7LfjUnB May 17 '16 at 04:00
  • Thanks , but I am not sure where this has to be updated in order to compute the load time for spring beans. – Punter Vicky May 17 '16 at 04:01