Spring 3+ Weblogic和JNDI问题

时间:2013-05-30 19:19:39

标签: spring weblogic jndi

这是我的第二个问题,希望有人会回答这个问题。      我正在使用weblogic 10和EJB 2,但现在我要在Spring 3中创建一个新模块。

一切正常但我无法在spring上下文xml中使用JNDI提供的现有数据源对象....

以下是文件

Weblogic config.xml

<jdbc-system-resource>
    <name>EOrderDataSource</name>
    <target>adeccoClubServer</target>
    <descriptor-file-name>jdbc/EOrderDataSource-jdbc.xml</descriptor-file-name>
  </jdbc-system-resource>
  <jdbc-system-resource>

EOrderDataSource-jdbc.xml中

<?xml version='1.0' encoding='UTF-8'?>
<jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/90" xmlns:sec="http://www.bea.com/ns/weblogic/90/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wls="http://www.bea.com/ns/weblogic/90/security/wls" xsi:schemaLocation="http://www.bea.com/ns/weblogic/920 http://www.bea.com/ns/weblogic/920.xsd">
  <name>EOrderDataSource</name>
  <jdbc-driver-params>
    <url>jdbc:oracle:thin:@dicmdb01:1512:o2ks1</url>
    <driver-name>oracle.jdbc.OracleDriver</driver-name>
    <properties>
      <property>
        <name>user</name>
        <value>asd</value>
      </property>
    </properties>
    <password-encrypted>asd</password-encrypted>
  </jdbc-driver-params>
  <jdbc-connection-pool-params>
    <initial-capacity>2</initial-capacity>
    <max-capacity>2</max-capacity>
    <capacity-increment>2</capacity-increment>
    <test-frequency-seconds>7200</test-frequency-seconds>
    <test-connections-on-reserve>true</test-connections-on-reserve>
    <test-table-name>DUAL</test-table-name>
  </jdbc-connection-pool-params>
  <jdbc-data-source-params>
    <jndi-name>EOrderDataSource</jndi-name>
    <global-transactions-protocol>EmulateTwoPhaseCommit</global-transactions-protocol>
  </jdbc-data-source-params>
</jdbc-data-source>

我的调度员servlet

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/jee
                        http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <mvc:annotation-driven/>
    <context:annotation-config />   

    <context:component-scan
        base-package="com.adecco.spring" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <jee:jndi-lookup id="dataSource" jndi-name="weboDataSource" expected-type="javax.sql.DataSource"/>

</beans>

Dispatcher Servet手动连接,工作正常

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <mvc:annotation-driven/>
    <context:annotation-config />   

    <context:component-scan
        base-package="com.adecco.spring" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@dicmdb01:1512:o2kd1" />
        <property name="username" value="abcd" />
        <property name="password" value="xyz" />
    </bean>
</beans>

即使在Java方面,它也非常简单地获取数据源对象并且工作正常:

Context ctx = new InitialContext ();

DataSource ds = (DataSource) ctx.lookup ("EOrderDataSource");

1 个答案:

答案 0 :(得分:0)

您的Spring配置中有jndi-name="weboDataSource",WebLogic配置中有<jndi-name>EOrderDataSource</jndi-name>。这些名称不匹配。