【发布时间】:2019-12-01 15:27:53
【问题描述】:
我正在尝试使用 JNDI 和 Spring 从 Tomcat 的 context.xml 加载 Marklogic ContentSource 对象。
我正在使用 Tomcat 8.5 和 Spring 2.5(很遗憾)
我在 Tomcat 的 context.xml 中添加了以下内容
<Resource name="MLContentSource" auth="Container" type="com.marklogic.xcc.ContentSource"
factory="com.marklogic.xcc.jndi.ContentSourceBeanFactory"
url="xcc://username:password@mymarklogic-server/DatabaseName"/>
我的 applicationContext.xml 中有以下内容
<bean id="contentSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/MLContentSource"/>
</bean>
我在 applicationContext.xml 中声明了另一个依赖于 ContentSource bean 的 bean。它期望设置一个类型为 com.marklogic.xcc.ContentSource
的属性<bean id="marklogicRepository" class="org.example.repository.ingestion.MarkLogicRepositoryImpl">
<property name="contentSource" ref="contentSource" />
</bean>
问题在于 contentSource bean 的类型是 JndiObjectFactoryBean 而不是 com.marklogic.xcc.ContentSource。我是否缺少从 JndiObjectFactoryBean 获取正确的 ContentSource 的东西?
【问题讨论】:
-
我之前没有尝试过使用 XCC 的 JNDI,但我会先编写一些在 Tomcat 中运行的自定义代码,并尝试通过 JNDI 手动获取 ContentSource。然后,修改自定义代码以使用 JndiObjectFactoryBean 来获取 ContentSource。如果这些都不起作用,则 Tomcat 配置有问题。如果这些工作 - 那么它似乎是如何配置 marklogicRepository 的问题。最坏的情况是,该 bean 可以从 Spring ApplicationContext 中检索“contentSource”bean 本身并从那里获取 ContentSource。
-
另外,你必须使用JDNI吗?我倾向于通过自定义 FactoryBean impl 构建 ContentSource,然后通过 Spring 属性获取配置详细信息。这在 Spring 2.5 中应该可以正常工作,只需要一个 PropertyPlaceholderConfigurer IIRC 从某个文件中读取属性。
标签: java spring tomcat jndi marklogic