在Liferay 6.2插件中获取JNDI数据源

时间:2015-12-17 00:22:51

标签: java spring liferay weblogic jndi

我有一个Liferay 6.2钩子,我试图在运行Liferay的Weblogic 12c容器中配置JNDI数据源。

数据源配置正确,可以在同一个Weblogic托管服务器上运行的其他Web应用程序访问,因此我知道这不是问题。

我正在使用Spring使用与服务器上运行的其他Web应用程序完全相同的配置来检索数据源。

我已使用与服务器上运行的其他Web应用程序完全相同的配置,将数据源声明为web.xml中的resource-ref。

我看到的错误信息是:

javax.naming.NameNotFoundException:尝试在/app/webapp/liferay-portal-6.2.0-ce-ga1.war/1037207272中查找comp / env / jdbc / bootstrap。剩余名称'comp / env / jdbc / bootstrap'

好像Weblogic的JNDI上下文不可用于钩子。

弹簧-config.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:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

<bean id="bootstrapDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/bootstrap"/>
</bean>

</beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<resource-ref>
    <description>Datasource</description>
    <res-ref-name>jdbc/bootstrap</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

</web-app>

由于 保罗

1 个答案:

答案 0 :(得分:0)

我从jndiName属性值中删除了“java:comp / env /”前缀。这解决了这个问题。这很奇怪,因为容器中的其他应用程序需要“java:comp / env /”前缀。

弹簧-config.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:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

<bean id="bootstrapDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/bootstrap"/>
</bean>

</beans>