【发布时间】:2016-09-12 23:56:59
【问题描述】:
我有一个由 100 多个 spring.xml 文件组成的应用程序。我想弄清楚加载这些spring.xml 文件中定义的所有beans 所花费的时间。请你让我知道如何做到这一点?谢谢!
【问题讨论】:
标签: java spring dependency-injection
我有一个由 100 多个 spring.xml 文件组成的应用程序。我想弄清楚加载这些spring.xml 文件中定义的所有beans 所花费的时间。请你让我知道如何做到这一点?谢谢!
【问题讨论】:
标签: java spring dependency-injection
long then = System.currentTimeMillis();
// 做你所有的事情
System.out.println("花费的毫秒数:" + System.currentTimeMillis() - then);
【讨论】:
您可以使用测试类计算 spring bean 加载时间。手动加载所有 xml 文件(不使用注释 - @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));
}
【讨论】: