Announcement Announcement Module
Collapse
No announcement yet.
ContextSingletonBeanFactoryLocator not finding beanRefContex Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ContextSingletonBeanFactoryLocator not finding beanRefContex

    Hi,
    I am having problems getting the ContextSingletonBeanFactoryLocator to load my beanRefContext.xml, I am using spring 1.1.5.

    I have this code
    Code:
            BeanFactoryLocator bfl = ContextSingletonBeanFactoryLocator.getInstance();
            BeanFactoryReference bf = bfl.useBeanFactory("com.ngms.dts.xqservice.xqutility");
    and this beanRefFactory.xml in the classpath
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
     <beans>
    
       <bean id="com.ngms.dts.xqservice.xqutility" lazy-init="true"
             class="org.springframework.context.support.ClassPathXmlApplicationContex">
         <constructor-arg>
           <list>
             <value>com/ngms/dts/xqservice/xqutility/applicationContext.xml</value>
    
           </list>
         </constructor-arg>
       </bean>
    
       <bean id="com.ngms.dts.xqservice.xqutility.mail" lazy-init="true"
             class="org.springframework.context.support.ClassPathXmlApplicationContex">
         <constructor-arg>
           <list>
             <value>com/ngms/dts/xqservice/xqutility/mail/applicationContext.xml</value>
           </list>
         </constructor-arg>
          <constructor-arg>
           <ref bean="com.ngms.dts.xqservice.xqutility"/>
         </constructor-arg>
       </bean>
    
     </beans>
    I get the following output when I run the code
    Code:
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
    INFO&#58; Bean factory for application context &#91;org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=1673361&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;&#93;; root of BeanFactory hierarchy
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.context.support.AbstractApplicationContext refresh
    INFO&#58; No beans defined in application context &#91;org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=1673361&#93;
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.core.CollectionFactory <clinit>
    INFO&#58; Using JDK 1.4 collections
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
    INFO&#58; Unable to locate MessageSource with name 'messageSource'&#58; using default &#91;[email protected]c&#93;
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
    INFO&#58; Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster'&#58; using default &#91;org.springframework.context.event.SimpleApplicationEventMulticaster@b6548&#93;
    Mar 27, 2005 4&#58;22&#58;25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO&#58; Pre-instantiating singletons in factory &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;&#93;; root of BeanFactory hierarchy&#93;
    Exception in thread "main" org.springframework.beans.FatalBeanException&#58; Unable to return specified BeanFactory instance&#58; factory key &#91;com.ngms.dts.xqservice.xqutility&#93;, from group with resource name &#91;classpath*&#58;beanRefContext.xml&#93;; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException&#58; No bean named 'com.ngms.dts.xqservice.xqutility' is defined&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;&#93;; root of BeanFactory hierarchy
    org.springframework.beans.factory.NoSuchBeanDefinitionException&#58; No bean named 'com.ngms.dts.xqservice.xqutility' is defined&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;&#93;; root of BeanFactory hierarchy
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition&#40;DefaultListableBeanFactory.java&#58;365&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition&#40;AbstractBeanFactory.java&#58;583&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;193&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;145&#41;
    	at org.springframework.context.support.AbstractApplicationContext.getBean&#40;AbstractApplicationContext.java&#58;504&#41;
    	at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory&#40;SingletonBeanFactoryLocator.java&#58;387&#41;
    	at com.ngms.dts.xqservice.xqutility.mail.EmailEncryptionService.init&#40;EmailEncryptionService.java&#58;26&#41;
    	at com.ngms.dts.xqservice.xqutility.mail.EmailEncryptionService.main&#40;EmailEncryptionService.java&#58;53&#41;
    It appears to not be finding the file, but I cannot figure out why. I've rechecked the paths to the applicationContext.xml's in question and they are where they are supposed to be.

    Any ideas?

    [/code]

  • #2
    You say that you have a definition file "beanRefFactory.xml" available on the classpath. That's the default name used by SingletonBeanFactoryLocator. However, you are using ContextSingletonBeanFactoryLocator, which looks by default for "beanRefContext". I believe you have an empty "beanRefContext.xml" file somewhere on the classpath, and that is what is being loaded... If this is the case, you just need to rename the non-empty file, and kile the empty one.

    Comment


    • #3
      Hi Colin,
      No I actually already had (and fixed) the beanRefFactory.xml vs beanRefContext.xml problem. Turns out reading is fundamental So I thought that would take care of it. But I am still getting the same error. Here's my build dir and I cat'ted the beanRefContext.xml

      Code:
      &#91;eoliphan-build&#93;&#58;find . -name *.xml
      ./classes/com/ngms/dts/xqservice/applicationContext.xml
      ./classes/com/ngms/dts/xqservice/xqsoap/rowsetwithdoccontent.xml
      ./classes/com/ngms/dts/xqservice/xqsoap/rowsetwithdoccontent2.xml
      ./classes/com/ngms/dts/xqservice/xqsoap/rowsetwithemptydoccontent.xml
      ./classes/com/ngms/dts/xqservice/xqutility/applicationContext.xml
      ./classes/com/ngms/dts/xqservice/xqutility/beanRefContext.xml
      ./classes/com/ngms/dts/xqservice/xqutility/mail/applicationContext.xml
      &#91;eoliphan-build&#93;&#58;cat ./classes/com/ngms/dts/xqservice/xqutility/beanRefContext.xml
      <?xml version="1.0" encoding="UTF-8"?>
       <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      
       <beans>
      
         <bean id="com.ngms.dts.xqservice.xqutility" lazy-init="true"
               class="org.springframework.context.support.ClassPathXmlApplicationContex">
           <constructor-arg>
             <list>
               <value>com/ngms/dts/xqservice/xqutility/applicationContext.xml</value>
      
             </list>
           </constructor-arg>
         </bean>
      
         <bean id="com.ngms.dts.xqservice.xqutility.mail" lazy-init="true"
               class="org.springframework.context.support.ClassPathXmlApplicationContex">
           <constructor-arg>
             <list>
               <value>com/ngms/dts/xqservice/xqutility/mail/applicationContext.xml</value>
             </list>
           </constructor-arg>
            <constructor-arg>
             <ref bean="com.ngms.dts.xqservice.xqutility"/>
           </constructor-arg>
         </bean>
      So I am still pulling my hair out as things seem to be in order.

      Comment


      • #4
        Problem solved, I moved the beanRefContext.xml to the default package and it's working. But I am a little confused, my interpretation of the docs was that Spring would search the classpath for the beanRefContext/Factory.xml file. Is this the case ?

        Thanks

        Comment


        • #5
          This is a pretty common mis-perception I think. Spring will look for this file at the root of each classpath entry (that is, in the root directory of each jar file). It won't do a search of every path (like /a/b/c...) to find all occurances of the file. That is not supported with the resource lookup mechanism.

          Comment


          • #6
            Originally posted by eoliphant
            Problem solved, I moved the beanRefContext.xml to the default package and it's working. But I am a little confused, my interpretation of the docs was that Spring would search the classpath for the beanRefContext/Factory.xml file. Is this the case ?

            Thanks
            There's no magic here. This is completely normal access to a resource on the classpath. When you try to load something from a classpath location, the actual package (if any) name of the resource needs to be specified as part of the resource name (i.e. package/anotherpackage/etc/resourceName). Now a classpath that is in use by a classloader may certainly include multiple base sources of resources (whether they be jar files or directory locations), but anything that is 'below' that location needs to be qualified with a package path to be found.






            There's actually no way in Java to

            Comment


            • #7
              Yes, I understand the normal resource lookup mechanism, I think i interpreted the 'classpath*' syntax as a search.

              Thanks for the clarification guys.

              Comment

              Working...
              X