在 beans.xml 之前加载 jndi.xml
我有两个文件 beans.xml 和 jndi.xml。我们想要检索 beans.xml 中通过 jndi.xml 放入 JNDI 的内容。不幸的是,beans.xml 中的 bean 是在加载 jndi.xml 之前创建的,因此当我们尝试在 beans.xml 中进行 JNDI 查找时,JNDI 中什么也没有。有没有办法让 jndi.xml 在 beans.xml 之前加载?
beans.xml
...
<bean id="geronimoTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/UserTransaction" />
</bean>
...
jndi.xml
<beans>
<bean id="jndi"
class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"
factory-method="makeInitialContext"
singleton="true">
<property name="entries" ref="jndiEntries" />
</bean>
<map id="jndiEntries">
<entry key="java:comp/UserTransaction" value-ref="geronimoTransactionManager" />
</map>
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="geronimoTransactionManager" />
</bean>
<bean id="geronimoTransactionManager" class="org.apache.geronimo.transaction.manager.TransactionManagerImpl" />
</beans>
这是让我相信 beans.xml 在 jndi.xml 之前加载的日志。
21:43:26,927 | INFO | l Console Thread | ultOsgiApplicationContextCreator | 72 - org.springframework.osgi.extender - 1.2.0 | Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [SWIM Prototype :: AqMqJDBC Pooling (camel-osgi-aqmq)]
21:43:26,939 | INFO | ExtenderThread-4 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Refreshing OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml): startup date [Wed Apr 20 21:43:26 GMT+00:00 2011]; root of context hierarchy
21:43:26,939 | INFO | ExtenderThread-4 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Unpublishing application context OSGi service for bundle SWIM Prototype :: AqMqJDBC Pooling (camel-osgi-aqmq)
21:43:26,973 | INFO | ExtenderThread-4 | XmlBeanDefinitionReader | 59 - org.springframework.beans - 3.0.5.RELEASE | Loading XML bean definitions from URL [bundleentry://202.fwk22939763/META-INF/spring/beans.xml]
21:43:27,295 | INFO | ExtenderThread-4 | CamelNamespaceHandler | 75 - org.apache.camel.camel-spring - 2.6.0.fuse-01-09 | OSGi environment detected.
21:43:29,167 | INFO | ExtenderThread-4 | WaiterApplicationContextExecutor | 72 - org.springframework.osgi.extender - 1.2.0 | No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml)
21:43:29,283 | INFO | ExtenderThread-5 | DefaultListableBeanFactory | 59 - org.springframework.beans - 3.0.5.RELEASE | Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@77e77a: defining beans [template,consumerTemplate,camel-1:beanPostProcessor,camel-1,required,jtaTransactionManager,geronimoTransactionManager,activeMQ,jmsConnectionFactory,jmsManagedConnectionFactory,jmsResourceAdapter,jencksConnectionManager,jencksPoolingSupport,requiredBeanForOracleAq,oracleQueue,oracleQueueCredentials,aqConnectionFactoryQueue,aqXADataSource,jdbcXADataSource,managedXADataSource,myTransform,preProps,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0]; root of factory hierarchy
21:43:29,736 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | JMX enabled. Using ManagedManagementStrategy.
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA UserTransaction: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA TransactionManager: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA TransactionSynchronizationRegistry: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:30,104 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Apache Camel 2.6.0-fuse-01-09 (CamelContext: 202-camel-3) is starting21:43:30,430 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 13 @Converter classes to load
21:43:30,469 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 1 @Converter classes to load
21:43:30,473 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 1 @Converter classes to load
21:43:30,477 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 2 @Converter classes to load
21:43:34,173 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Route: route1 started and consuming from: Endpoint[activeMQ://queue:BROKER2.QUEUE?concurrentConsumers=10]
21:43:34,194 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Total 1 routes, of which 1 is started.
21:43:34,196 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Apache Camel 2.6.0-fuse-01-09 (CamelContext: 202-camel-3) started in 4.089 seconds
21:43:34,204 | INFO | ExtenderThread-5 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Publishing application context as OSGi service with properties {org.springframework.context.service.name=camel-osgi-aqmq, Bundle-SymbolicName=camel-osgi-aqmq, Bundle-Version=4.3.0.fuse-03-00}
21:43:34,205 | INFO | ExtenderThread-5 | ContextLoaderListener | 72 - org.springframework.osgi.extender - 1.2.0 | Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml))
21:43:41,674 | INFO | tenerContainer-7 | SpringInitialContextFactory | 110 - org.apache.xbean.spring - 3.7 | Loading JNDI context from: class path resource [jndi.xml]
21:43:41,685 | INFO | tenerContainer-7 | XBeanXmlBeanDefinitionReader | 59 - org.springframework.beans - 3.0.5.RELEASE | Loading XML bean definitions from class path resource [jndi.xml]
I have two files beans.xml and jndi.xml. We want to retrieve something in beans.xml that is put into JNDI through jndi.xml. Unfortunately, beans in beans.xml are created before jndi.xml is loaded, so when we try to do the JNDI lookup in beans.xml, nothing is in JNDI. Is there a way to get jndi.xml to be loaded before beans.xml?
beans.xml
...
<bean id="geronimoTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/UserTransaction" />
</bean>
...
jndi.xml
<beans>
<bean id="jndi"
class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"
factory-method="makeInitialContext"
singleton="true">
<property name="entries" ref="jndiEntries" />
</bean>
<map id="jndiEntries">
<entry key="java:comp/UserTransaction" value-ref="geronimoTransactionManager" />
</map>
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="geronimoTransactionManager" />
</bean>
<bean id="geronimoTransactionManager" class="org.apache.geronimo.transaction.manager.TransactionManagerImpl" />
</beans>
Here is the log that makes me believe beans.xml is loaded before jndi.xml.
21:43:26,927 | INFO | l Console Thread | ultOsgiApplicationContextCreator | 72 - org.springframework.osgi.extender - 1.2.0 | Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [SWIM Prototype :: AqMqJDBC Pooling (camel-osgi-aqmq)]
21:43:26,939 | INFO | ExtenderThread-4 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Refreshing OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml): startup date [Wed Apr 20 21:43:26 GMT+00:00 2011]; root of context hierarchy
21:43:26,939 | INFO | ExtenderThread-4 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Unpublishing application context OSGi service for bundle SWIM Prototype :: AqMqJDBC Pooling (camel-osgi-aqmq)
21:43:26,973 | INFO | ExtenderThread-4 | XmlBeanDefinitionReader | 59 - org.springframework.beans - 3.0.5.RELEASE | Loading XML bean definitions from URL [bundleentry://202.fwk22939763/META-INF/spring/beans.xml]
21:43:27,295 | INFO | ExtenderThread-4 | CamelNamespaceHandler | 75 - org.apache.camel.camel-spring - 2.6.0.fuse-01-09 | OSGi environment detected.
21:43:29,167 | INFO | ExtenderThread-4 | WaiterApplicationContextExecutor | 72 - org.springframework.osgi.extender - 1.2.0 | No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml)
21:43:29,283 | INFO | ExtenderThread-5 | DefaultListableBeanFactory | 59 - org.springframework.beans - 3.0.5.RELEASE | Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@77e77a: defining beans [template,consumerTemplate,camel-1:beanPostProcessor,camel-1,required,jtaTransactionManager,geronimoTransactionManager,activeMQ,jmsConnectionFactory,jmsManagedConnectionFactory,jmsResourceAdapter,jencksConnectionManager,jencksPoolingSupport,requiredBeanForOracleAq,oracleQueue,oracleQueueCredentials,aqConnectionFactoryQueue,aqXADataSource,jdbcXADataSource,managedXADataSource,myTransform,preProps,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0]; root of factory hierarchy
21:43:29,736 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | JMX enabled. Using ManagedManagementStrategy.
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA UserTransaction: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA TransactionManager: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:29,839 | INFO | ExtenderThread-5 | JtaTransactionManager | 74 - org.springframework.transaction - 3.0.5.RELEASE | Using JTA TransactionSynchronizationRegistry: org.apache.geronimo.transaction.manager.TransactionManagerImpl@1f07586
21:43:30,104 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Apache Camel 2.6.0-fuse-01-09 (CamelContext: 202-camel-3) is starting21:43:30,430 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 13 @Converter classes to load
21:43:30,469 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 1 @Converter classes to load
21:43:30,473 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 1 @Converter classes to load
21:43:30,477 | INFO | ExtenderThread-5 | Activator | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Found 2 @Converter classes to load
21:43:34,173 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Route: route1 started and consuming from: Endpoint[activeMQ://queue:BROKER2.QUEUE?concurrentConsumers=10]
21:43:34,194 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Total 1 routes, of which 1 is started.
21:43:34,196 | INFO | ExtenderThread-5 | OsgiSpringCamelContext | 68 - org.apache.camel.camel-core - 2.6.0.fuse-01-09 | Apache Camel 2.6.0-fuse-01-09 (CamelContext: 202-camel-3) started in 4.089 seconds
21:43:34,204 | INFO | ExtenderThread-5 | OsgiBundleXmlApplicationContext | 61 - org.springframework.context - 3.0.5.RELEASE | Publishing application context as OSGi service with properties {org.springframework.context.service.name=camel-osgi-aqmq, Bundle-SymbolicName=camel-osgi-aqmq, Bundle-Version=4.3.0.fuse-03-00}
21:43:34,205 | INFO | ExtenderThread-5 | ContextLoaderListener | 72 - org.springframework.osgi.extender - 1.2.0 | Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=camel-osgi-aqmq, config=osgibundle:/META-INF/spring/*.xml))
21:43:41,674 | INFO | tenerContainer-7 | SpringInitialContextFactory | 110 - org.apache.xbean.spring - 3.7 | Loading JNDI context from: class path resource [jndi.xml]
21:43:41,685 | INFO | tenerContainer-7 | XBeanXmlBeanDefinitionReader | 59 - org.springframework.beans - 3.0.5.RELEASE | Loading XML bean definitions from class path resource [jndi.xml]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 jndi.xml 中,您应该尝试:
In jndi.xml, you should try :