如何在Spring中使用WebLogic 12.2.1提供的JNDI DataSource?

Raj*_*ula 5 java spring jndi weblogic12c

我使用以下值创建了JNDI连接:

我选择了Generic Data Source选项

名称:jdbc/sampleDataSource

JNDI名称:jdbc/sampleDataSource

Spring配置文件:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/sampleDataSource" />

我低于错误.

Error An error occurred during activation of changes, please see the log for details.
Error javax.naming.NameNotFoundException: While trying to lookup 'jdbc.sampleDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/sampleDataSource'
Error While trying to lookup 'jdbc.sampleDataSource' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/sampleDataSource' 
Run Code Online (Sandbox Code Playgroud)

我无法解决它.我如何在Spring 4中配置.任何添加jar文件都是必需的.请帮忙.

STa*_*efi 5

有时,当您忘记Target定义datasource到特定服务器时,就会发生这种情况。您可以在Weblogic的管理服务器中找到它:

在此处输入图片说明

然后在Targets标签中:

在此处输入图片说明

您应该选择目标。

如果这不是问题,您可以尝试让你的方式datasourceapplicationContext.xml

<bean id="dataSource" name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/mcdsDS"/>
    <property name="resourceRef" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

并在需要的地方使用dataSource参考datasource

希望这会有所帮助。