-1

I need to get the context xml file locations from ClassPathXmlApplicationContext instance.

When I inspected the source code, I saw that "configLocations" array ,which contains the locations of the files, are private and the getConfigLocations method is protected.

Is there any other way to get these location?

Thx

Ali

Neron
  • 1,500
  • 7
  • 30
  • 52

1 Answers1

0

As we use ClassPathXmlApplicationContext constructor to construct context, we need supply the context xml file, so I assume that you already know the file name of the context xml file. If you want to get the absolute file path, you can use this method Resource getResource(String location) (which defined in the ResourceLoader interface implemented by ClassPathXmlApplicationContext), and use the method File getFile() throws IOException; defined in Resource to get the File object, and invoke getAbsolutePath to retrieve the full path.

CNiq527
  • 11
  • 2