java - how to know resource from which a bean is loaded in spring project. -


I am new to the spring structure. I want to know the list of referenced XML files while loading beans.

By writing a class that is ApplicationContextAware, I am able to see the list of beans:

  @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration ("ClassPath: Spring / Spring-Test Contrast. XML ") Public Class Sample Application ApplicationContextAware {@Autowired ApplicationContext applicationContext; @Test Public Invalid testMethod () {for (string name: applicationContext.getBeanDefinitionNames ()) {System.out.println ("BeanName" + beanName); }}}   

But I want to know which configuration files beans are loaded

Say "sample-testcontext.xml"

  & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Beans: beans xmlns: beans = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: reference = "Http: //www.springframework.org/schema/context "xmlns: util =" http://www.springframework.org/schema/util "xsi: schema location =" http://www.springframework.org/schema/sem Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring - context-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/ use Http://www.springframework.org/schema/util/spring-util-3.0.xsd"> & Lt; Beans: Import Resources = "Squared *: Spring / Sample-Tested Onmorecontext.xml" /> & Lt; / Bean: beans & gt;   

I want to know the list of file names from which the beans are loaded in the form of "sample-testonmorecontex.xml" and "sample-testcontext.xml".

Why do you want to do this? I'm not sure that the internal implementation keeps records of that information when the context is implemented. However, there is a way to know how resources have a special bean loaded. This can be useful if you have definitions of many bean with the same name and you want to know who has "won".

Take back your example (BTW, you

  @ContextConfiguration @ContextConfiguration ("ClassPath: Spring / Spring-TestConnectX.Xml") Public Category Sample Test {@ Etvoir private configuration episode contact reference; @Test public void foo () {ConfigurableListibleBinFeeterBenFactor = Reference.GetBenFactors (); (String Name: context.getBeanDefinitionNames ()) {System.out.println (beanName + "- & gt; "+ BeanFactory.getBeanDefinition (exclamation) .getRes OurceDescription ());}}}   

This gives you something (except for the definitions of internal post processor bean that the default implementation can be registered automatically)

  beanFirst -> class organization SamplingTest $ ConfigBencecend -> Category Path Resource [foobar.xml]   

Where BeenFirst will test Was loaded from the internal class (which is called Config ) and Binsecond from a file called foobar.xml At the root of Laspath was loaded.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -