0

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

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

这是文件

Weblogic 配置.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");
4

1 回答 1

0

jndi-name="weboDataSource"在 spring 配置和<jndi-name>EOrderDataSource</jndi-name>WebLogic 配置中都有。这些名称不匹配。

于 2013-05-30T20:21:49.647 回答