Announcement Announcement Module
Collapse
No announcement yet.
properties ref fail Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • properties ref fail

    I'm using Spring 1.1.1, and have some trouble with ref, because I want share some properties to all my JndiObject. my applicationContext-jms.xml
    Code:
        <bean id="QMTestCF" class="org.springframework.jndi.JndiObjectFactoryBean">
        	<property name="jndiEnvironment"><ref local="ref"/></property>    		
            <property name="jndiName"><value>cn=QM_Test,cn=jms,cn=thailh</value></property>
        </bean>
        
    	<bean id="ref" class="java.util.Properties">
    		<constructor-arg>
    			<props>
    				<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
        			<prop key="java.naming.provider.url">ldap&#58;//192.100.100.12&#58;389/dc=cicat,dc=com</prop>
    			</props>
    		</constructor-arg>
    	</bean>
    when i run some test:
    Code:
    FileSystemXmlApplicationContext context = 
                new FileSystemXmlApplicationContext&#40;"/Web Content/WEB-INF/classes/applicationContext-jms.xml"&#41;;
    i've got Exception:
    Oct 4, 2004 2:53:04 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'QMTestCF'
    Oct 4, 2004 2:53:05 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
    INFO: Creating shared instance of singleton bean 'ref'
    Oct 4, 2004 2:53:05 PM org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory autowireConstructor
    INFO: Bean 'ref' instantiated via constructor [public java.util.Properties(java.util.Properties)]
    Oct 4, 2004 2:53:05 PM org.springframework.beans.factory.support.Abstract BeanFactory destroySingletons
    INFO: Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [QMTestCF,reply,request,test,ref]; Root of BeanFactory hierarchy}
    Oct 4, 2004 2:53:05 PM org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory destroySingletons
    INFO: Destroying inner beans in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [QMTestCF,reply,request,test,ref]; Root of BeanFactory hierarchy}
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'QMTestCF' defined in file [D:\eclipse\workspace\mqdemo\Web Content\WEB-INF\classes\applicationContext-jms.xml]: Initialization of bean failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:653)
    at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:257)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx (InitialContext.java:294)
    at javax.naming.InitialContext.lookup(InitialContext. java:361)
    at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:123)
    at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:85)
    at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:121)
    at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:71)
    at org.springframework.jndi.JndiObjectLocator.lookup( JndiObjectLocator.java:85)
    at org.springframework.jndi.JndiObjectFactoryBean.aft erPropertiesSet(JndiObjectFactoryBean.java:59)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1057)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:287)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:205)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:204)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:136)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:230)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:284)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:83)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:68)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:59)
    at com.cicat.mqdemo.test.JmsMessager.main(JmsMessager .java:33)

  • #2
    since java.util.Properties extends java.util.Hashtable, you can use the following workaround:
    Code:
      <bean id="ref" class="java.util.Hashtable">
        <constructor-arg>
          <map>
            <entry key="java.naming.factory.initial">
              <value>com.sun.jndi.ldap.LdapCtxFactory</value>
            </entry>
            <entry key="java.naming.provider.url">
              <value>ldap&#58;//192.100.100.12&#58;389/dc=cicat,dc=com</value>
            </entry>
          </map>
        </constructor-arg>
      </bean>
    <bean id="ref" class="java.util.Properties">
    <constructor-arg>
    <props>
    <prop key="java.naming.factory.initial">com.sun.jndi.lda p.LdapCtxFactory</prop>
    <prop key="java.naming.provider.url">ldap://192.100.100.12:389/dc=cicat,dc=com</prop>
    </props>
    </constructor-arg>
    </bean>
    actually, this declaration will be executed as
    Code:
      Properties ref = new Properties&#40;props&#41;;
      //ref.isEmpty&#40;&#41; returns true
    which is very different from
    Code:
      Properties ref = new Properties&#40;&#41;;
      ref.putAll&#40;props&#41;;
      //ref.isEmpty&#40;&#41; returns false
    HTH

    Comment


    • #3
      thank you, now i am understand it, no more wonder. Another way working well is
      Code:
          <bean id="baseJNDI"  abstract="true">    	
      		<property name="jndiEnvironment">
          		<props>
      				<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
          			<prop key="java.naming.provider.url">ldap&#58;//192.100.100.12&#58;389/dc=cicat,dc=com</prop>
      			</props>
      		</property>
      	</bean>	
      
          <bean id="QMTestCF" parent="baseJNDI" class="org.springframework.jndi.JndiObjectFactoryBean">    		
              <property name="jndiName"><value>cn=QM_Test,cn=jms,cn=thailh</value></property>
          </bean>
      but I have Problem, but it does't matter:
      Code:
      Severity	Description	Resource	In Folder	Location	Creation Time
      2	Attribute "abstract" must be declared for element type "bean".	applicationContext-jms.xml	mqdemo/Java Source	line 21	October 5, 2004 12&#58;04&#58;07 PM

      Comment


      • #4
        to use abstract, you need to migrate / upgrade Spring Framework to version 1.1

        Comment

        Working...
        X