oracle – Liferay portlet非liferay JNDI数据源null

前端之家收集整理的这篇文章主要介绍了oracle – Liferay portlet非liferay JNDI数据源null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于访问非liferay Oracle数据库的Liferay 6.2自定义portlet,我们遇到的问题是返回的数据源为null.

我们已经配置了tomcat / conf / context.xml

  1. <!-- Adding custom New non liferay datasource -->
  2. <Resource name="jdbc/NewPool"
  3. auth="Container"
  4. type="javax.sql.DataSource"
  5. driverClassName="oracle.jdbc.OracleDriver"
  6. url="jdbc:oracle:thin:@(DESCRIPTION =
  7. (ADDRESS = (PROTOCOL = TCP)(HOST = dbservernameorip)(PORT = 9999))
  8. (CONNECT_DATA = (SERVER = DEDICATED)
  9. (SERVICE_NAME = dbSIDorservicename)))"
  10. username="user"
  11. password="pwd"
  12. maxActive="35"
  13. maxIdle="10"
  14. maxWait="20000"
  15. removeAbandoned="true"
  16. logAbandoned="true"
  17. minEvictableIdleTimeMillis="3600000"
  18. timeBetweenEvictionRunsMillis="1800000"
  19. testOnBorrow="true"
  20. testOnReturn="false"
  21. />

portlet web.xml包含:

  1. <resource-ref>
  2. <description>Oracle Datasource example</description>
  3. <res-ref-name>jdbc/NewPool</res-ref-name>
  4. <res-type>javax.sql.DataSource</res-type>
  5. <res-auth>Container</res-auth>
  6. </resource-ref>

查找代码是:

  1. String JNDI = "jdbc/NewPool"
  2. _log.debug("JNDI Name is: " + JNDI);
  3. _log.debug("dataSource in dbConnect is :" + dataSource);
  4. Context context = new InitialContext();
  5. Context envContext = (Context)context.lookup("java:/comp/env");
  6. _log.debug("envContext in dbConnect is :" + envContext);
  7. try {
  8. DataSource ds = (DataSource)envContext.lookup(JNDI);

Liferay可以成功地将context.xml资源与Liferay Oracle数据库的类似数据源一起使用.

Liferay portlet是否需要一些其他布线来建立与另一个数据库的连接?

在没有web.xml更改的情况下,相同的portlet代码适用于weblogic.类似的JNDI数据源查找代码和配置适用于vanilla tomcat(没有liferay)和普通war(非liferay portlet)文件.

更新:

我已经使用netstat -an | grep dbport检查了服务器上的数据库连接.这并未显示已建立的连接.

我还尝试在portal-ext.properties中设置portal.security.manager.strategy = none.这也不起作用.

我们非常感激任何见解,因为我们有点困在这里.

谢谢!

我刚刚在Liferay论坛中偶然发现了这个主题.在你的tomcat / conf / server.xml中选择它
  1. <GlobalNamingResources>
  2. <!-- Editable user database that can also be used by
  3. UserDatabaseRealm to authenticate users
  4. -->
  5. <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  6.  
  7. <Resource name="jdbc/XXX" auth="Container" type="javax.sql.DataSource"
  8. maxActive="20" maxIdle="10" maxWait="5000"
  9. removeAbandoned="true" removeAbandonedTimeout="250" validationQuery="SELECT 1"
  10. username="user2" password="pwd2"
  11. driverClassName="com.MysqL.jdbc.Driver"
  12. url="jdbc:MysqL://localhost/myOtherDb"/>

这在你的context.xml中:

  1. <ResourceLink name="jdbc/XXX" global="jdbc/XXX" type="javax.sql.DataSource">

它应该做的伎俩.如果你真的问为什么Liferay可以找到jndi资源,而不是你的portlet:我没有线索…

猜你在找的Oracle相关文章