对于访问非liferay Oracle数据库的Liferay 6.2自定义portlet,我们遇到的问题是返回的数据源为null.
我们已经配置了tomcat / conf / context.xml
- <!-- Adding custom New non liferay datasource -->
- <Resource name="jdbc/NewPool"
- auth="Container"
- type="javax.sql.DataSource"
- driverClassName="oracle.jdbc.OracleDriver"
- url="jdbc:oracle:thin:@(DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = dbservernameorip)(PORT = 9999))
- (CONNECT_DATA = (SERVER = DEDICATED)
- (SERVICE_NAME = dbSIDorservicename)))"
- username="user"
- password="pwd"
- maxActive="35"
- maxIdle="10"
- maxWait="20000"
- removeAbandoned="true"
- logAbandoned="true"
- minEvictableIdleTimeMillis="3600000"
- timeBetweenEvictionRunsMillis="1800000"
- testOnBorrow="true"
- testOnReturn="false"
- />
portlet web.xml包含:
- <resource-ref>
- <description>Oracle Datasource example</description>
- <res-ref-name>jdbc/NewPool</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
查找代码是:
- String JNDI = "jdbc/NewPool"
- _log.debug("JNDI Name is: " + JNDI);
- _log.debug("dataSource in dbConnect is :" + dataSource);
- Context context = new InitialContext();
- Context envContext = (Context)context.lookup("java:/comp/env");
- _log.debug("envContext in dbConnect is :" + envContext);
- try {
- 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中选择它
- <GlobalNamingResources>
- <!-- Editable user database that can also be used by
- UserDatabaseRealm to authenticate users
- -->
- <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"/>
- <Resource name="jdbc/XXX" auth="Container" type="javax.sql.DataSource"
- maxActive="20" maxIdle="10" maxWait="5000"
- removeAbandoned="true" removeAbandonedTimeout="250" validationQuery="SELECT 1"
- username="user2" password="pwd2"
- driverClassName="com.MysqL.jdbc.Driver"
- url="jdbc:MysqL://localhost/myOtherDb"/>
这在你的context.xml中:
- <ResourceLink name="jdbc/XXX" global="jdbc/XXX" type="javax.sql.DataSource">
它应该做的伎俩.如果你真的问为什么Liferay可以找到jndi资源,而不是你的portlet:我没有线索…