Java classpath used by Spring

大兔子大兔子 提交于 2019-12-24 12:51:11

问题


I know a way to print the classpath of a project at runtime like here:

http://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/

But sometimes the main is even too late, for example when using spring.

Is there a way to print something(e.g. classpath) even before Spring starts the injection process?

Providing some context, i am running a unit test in spring as follows:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/jmsAppContext.xml")
public class TestProjectProvisioningIntegration
{
....

}

It finds correctly the jmsAppContext.xml, but fails to find one of the properties files.


回答1:


To get the same effect as you have in the link you posted, you could get the classpath in a static initializer (just do the same as the example, only then in a static { ... } block instead of a main method. The JVM will execute the static initializer first, before loading any other classes your class depends on (other than the classes you reference in the static initializer).



来源:https://stackoverflow.com/questions/24313701/java-classpath-used-by-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!