在我的项目中,我使用第三方jar。这个jar依赖于jndi.xml和jndi.properties文件。
独立第三方罐子的结构:
/
|- TP.jar
|- jndi.xml
|- jndi.properties
在这个jar的applicationContext中 - 有一个对jndi.xml中创建的bean的引用 这个jar是用ant构建的,构建工作正常。
我在我的maven项目中将此jar包含为依赖项。在我的maven项目dispatcher-servlet中,导入TP.jar的applciation上下文以访问TP.jar中的bean。
我的maven项目的部署失败,出现以下错误:
javax.naming.NameNotFoundException: Name [JNDIDatasource] is not bound in this Context. Unable to find [JNDIDatasource].
jndi.properties:
java.naming.factory.initial=org.apache.xbean.spring.jndi.SpringInitialContextFactory
jndi.xml:
<beans>
<bean class="org.apache.xbean.spring.jndi.DefaultContext" id="jndi">
<property name="entries">
<map>
<entry key="JNDIDatasource">
<bean class="org.apache.tomcat.dbcp.dbcp.BasicDataSource" destroy-method="close" singleton="false">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://<host>:1433;DatabaseName=test"></property>
-----
</bean>
</entry>
-----------
</bean>
--------------
</beans>
TP.jar applicationContext.xml:
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="JNDIDatasource" />
</bean>
当在我的maven项目中导入上面的applicationContext时,tomcat不会启动。 我非常关注如何解决这个问题,任何帮助都会受到高度赞赏。
我尝试将jndi.xml和jndi.properties添加到 src / main / resources 下的maven项目中,希望它们将包含在我的maven项目的路径中,并且bean可能会被发现。但这没有帮助。
答案 0 :(得分:0)
我在我的申请中这样做了。
申请背景
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx
..
http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
">
<jee:jndi-lookup id="cdrDataSource" jndi-name="jdbc/cdr_source" resource-ref="true" />
</beans>
jndi.properties
java.naming.factory.initial=org.apache.xbean.spring.jndi.SpringInitialContextFactory
java.naming.provider.url = classpath:/jndi.xml
<强> jndi.xml 强>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd ">
<bean id="jndi" class="org.apache.xbean.spring.jndi.DefaultContext">
<property name="entries">
<map>
<entry key="jdbc/cdr">
<bean class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>net.sourceforge.jtds.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:jtds:sybase://server:7306/cdr</value>
</property>
....
客户来电
@Repository
public class CDRDataRetriever {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Resource(name = "cdrDataSource")
private DataSource cdrDataSource;