I believe there is an issue with Liferay 6.1 CE GA2 and the Tomcat bundle. Specifically, it seems to have broken the use of JNDI resources by servlets and portlets. I found this in a portlet that worked in GA1 but not in GA2.
Clarification: The example uses SQL embedded in a JSP to demonstrate the failure of GA2 in the simplest possible way. It's a horrible practice!
I created a simple war file that uses JNDI per the instructions in
Tomcat 7 JNDI Datasource How-To, using MySQL. I did this to eliminate any issues with Liferay, Hibernate or other libraries. The resulting war file consists of three files (plus two jars). The war file is attached, but you'll have to set your own username and password to get it to work. The MySQL drivers have also been placed in both lib and lib/ext just to eliminate any classpath issues.
If you copy the war file to the webapp directory of Liferay 6.1 CE GA1 or vanilla copies of Tomcat 7.0.23 (same as GA1) or Tomcat 7.0.27 (same as GA2) or even Tomcat 7.0.32, you can open http://localhost:8080/test/test.jsp and get the results you would expect. However, if you do the same thing with Liferay 6.1 CE GA2, you get the following exception:
1javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/MySqlDS"
2 org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:318)
3 org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:201)
4 org.apache.jsp.test_jsp._jspx_meth_sql_005fquery_005f0(test_jsp.java:119)
5 org.apache.jsp.test_jsp._jspService(test_jsp.java:72)
The three files are context.xml (you may need to copy this as test.xml to conf/Catalina/localhost), web.xml, and test.jsp.
context.xml:
1<?xml version='1.0' encoding='utf-8'?>
2<Context>
3 <Resource name="jdbc/MySqlDS" auth="Container"
4 type="javax.sql.DataSource"
5 factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
6 driverClassName="com.mysql.jdbc.Driver"
7 username="user"
8 password="password"
9 url="jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&relaxAutoCommit=true"
10 maxActive="200" maxIdle="30" maxWait="10000"
11 minIdle="3"
12 testWhileIdle="true" testOnBorrow="true"
13 timeBetweenEvictionRunsMillis="120000"
14 minEvictableIdleTimeMillis="600000"
15 validationQuery="select 1"
16 />
17 <!-- Default set of monitored resources -->
18 <WatchedResource>WEB-INF/web.xml</WatchedResource>
19</Context>
web.xml:
1<?xml version="1.0" encoding="UTF-8"?>
2<web-app version="3.0"
3 xmlns="http://java.sun.com/xml/ns/javaee"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
7 <display-name></display-name>
8 <resource-ref>
9 <description>DB Connection</description>
10 <res-ref-name>jdbc/MySqlDS</res-ref-name>
11 <res-type>javax.sql.DataSource</res-type>
12 <res-auth>Container</res-auth>
13 </resource-ref>
14 <welcome-file-list>
15 <welcome-file>test.jsp</welcome-file>
16 </welcome-file-list>
17</web-app>
test.jsp:
1<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
2<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3
4<sql:query var="rs" dataSource="jdbc/MySqlDS">
5select foodItemId, name_, points from fooditem
6</sql:query>
7
8<html>
9 <head>
10 <title>DB Test</title>
11 </head>
12 <body>
13
14 <h2>Results</h2>
15
16<c:forEach var="row" items="${rs.rows}">
17 Id ${row.foodItemId}<br/>
18 Name ${row.name_}<br/>
19 Points ${row.points}<br/>
20</c:forEach>
21
22 </body>
23</html>
I suppose I could be doing something wrong, but I certainly don't know what that is. Thanks.
Bitte melden Sie sich an, um diesen Inhalt als unangebracht zu kennzeichnen.