留言板

Tomcat connection pool error in DXP

Jatinderveer Singh,修改在6 年前。

Tomcat connection pool error in DXP

New Member 帖子: 21 加入日期: 17-2-24 最近的帖子
I have a JNDI connection pool defined at Tomcat level . When i start the server the connection pool is set up and no error is thrown but when i try to retrieve the same pool from my portlet using a simple java class i get the following error

java.lang.ClassCastException: org.apache.naming.ResourceLinkRef cannot be cast to javax.sql.DataSource 
        at com.test.HbaseUtil.openConnection(HbaseUtil.java:55) 
        at com.test.DAOImpl.getDetails(DAOImpl.java:112) 
        at com.test.HomeMBean.getDetails(HomeMBean.java:341) 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 


Is there something in particular that i need to take care of when my portlet is deployed in OSGI framework to get this working. The same code was working in Liferay 6.2 and is working in vanilla Tomcat 8.
Kristina la pietra,修改在6 年前。

RE: Tomcat connection pool error in DXP

New Member 发布: 1 加入日期: 13-3-26 最近的帖子
Hi,
I have the same problem with liferay 7 ga3 and tomcat8 . Also for me the same configuration correctaly work in liferay 6.2.
I have the same problem both with hibernate configuration and with Spring. With Hibernate I tested the connection using jdbc and it works.
Lavanya Chimata,修改在6 年前。

RE: Tomcat connection pool error in DXP

New Member 帖子: 2 加入日期: 14-10-2 最近的帖子
We are experiencing similar issue. Is it resolved for you?
thumbnail
Olaf Kock,修改在6 年前。

RE: Tomcat connection pool error in DXP

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Jatinderveer Singh:

java.lang.ClassCastException: org.apache.naming.ResourceLinkRef cannot be cast to javax.sql.DataSource 
        at com.test.HbaseUtil.openConnection(HbaseUtil.java:55) 
        at com.test.DAOImpl.getDetails(DAOImpl.java:112) 
        at com.test.HomeMBean.getDetails(HomeMBean.java:341) 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 



While the original question is somewhat old, after two more having stated "the same" problem, I'd like to ask for more information - everybody who posted here:

  • Are you sure you have the same problem? With code from the com.test package? At least this is not part of Liferay
  • Your configuration might have been worked with Liferay 6.2, but that might also have been on a different tomcat version. You don't give any hint about the configuration you're using, no steps to reproduce
Dipak Ahuja,修改在3 年前。

RE: Tomcat connection pool error in DXP

New Member 帖子: 7 加入日期: 20-7-22 最近的帖子
Yes Olaf, it works fine for me with Liferay 6.1, whereas the same issue I observed with Liferay 7.3 and tomcat 9. Please find below the configuration for server.xml and portlet-application-context.xml respectively.

server.xml

<Resource name="jdbc/LiferayPool"
              global="jdbc/LiferayPool"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              auth="Container"
              type="javax.sql.DataSource"             
              username="root"
              password="root"
              driverClassName="com.mysql.cj.jdbc.Driver"
              description="Liferay database."
              url="jdbc:mysql://localhost:3305/lportal731?autoReconnect=true"
              testWhileIdle="true"
              testOnBorrow="true"/>

context.xml   

<ResourceLink name="jdbc/LiferayPool" global="jdbc/LiferayPool" type="javax.sql.DataSource"/>
portlet-application-context.xml
<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/LiferayPool"/>
    </bean>
    <bean id="hibernateJpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="jndiDataSource" />
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
        <property name="packagesToScan" value="com.nividous.rpa.domain" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">false</prop>
            </props>
        </property>
    </bean>

Thanks in advance.

Cheers,
Dipak
thumbnail
David H Nebinger,修改在3 年前。

RE: Tomcat connection pool error in DXP

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
The JNDI context for the app server is not exposed into the OSGi container. In order to get to it you have to use the Portal's class loader, something the JndiObjectFactoryBean has no idea how to do.

You have to use your own implementation of that class that knows how to temporarily switch to the portal class loader when doing the JNDI lookup and restoring on return.