2011-09-01 6 views
15

webapp의 .jsp 페이지를 통해 postgresql db에 연결하는 JNDI 데이터 소스에 액세스 할 때마다 Tomcat 7.0.12를 사용하고이 오류가 발생합니다.''연결 URL에 대해 ''의 JDBC 드라이버를 만들 수 없습니다. '

SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception 
[java.lang.RuntimeException: Cannot create JDBC driver of class '' for connect URL 'null'] with root cause 
java.lang.NullPointerException 
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) 
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) 
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) 
at java.sql.DriverManager.getDriver(DriverManager.java:253) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) 
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 

postgresql JDBC 드라이버는 내 CATALINA/lib 폴더에 있습니다. 나는이 개 다른 웹 어플리케이션을 가지고

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

<resource-ref> 
    <description>Read only webdb connector.</description> 
    <res-ref-name>jdbc/webdbro</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 
<resource-ref> 
    <description>Read write webdb connector.</description> 
    <res-ref-name>jdbc/webdbrw</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 
<resource-ref> 
    <description>Read only shadow db connector.</description> 
    <res-ref-name>jdbc/shadowdbro</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

</web-app> 

이상한 것은이 : 여기

<?xml version="1.0" encoding="UTF-8"?> 

<Context> 

<Resource name="jdbc/webdbro" auth="Container" type="javax.sql.DataSource" 
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/webdb" 
    username="webdbro" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/> 

<Resource name="jdbc/webdbrw" auth="Container" type="javax.sql.DataSource" 
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/webdb" 
    username="webdbrw" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/> 

<Resource name="jdbc/shadowdbro" auth="Container" type="javax.sql.DataSource" 
    driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/shadowdb" 
    username="shadowdbro" password="pass" maxWait="-1" removeAbandoned="true" removeAbandonedTimeout="30"/> 

</Context> 

내 WEB-INF/web.xml에있다 : 여기

내 META-INF/context.xml에있다 동일한 구성 (web.xml 및 context.xml)을 사용하여 동일한 Tomcat 서버에서 실행되므로 JNDI 방법을 사용하여 데이터베이스에 연결할 수 있으며 두 웹 응용 프로그램 모두 완벽하게 작동합니다. 데이터베이스를 쿼리하고 업데이트 할 수 있습니다. 문제 또는 예외를 TIA ...

+0

예외는 Tomcat이 사용자가 구성한 ''을 읽거나 발견하지 못했음을 나타냅니다. Eclipse 내부에서 웹 애플리케이션을 실행하고 있습니까? – BalusC

답변

17

모든 웹 응용 프로그램에 동일한 데이터 소스를 올바르게 사용하려면 META-INF/context.xml 폴더의 모든 <Resource> 항목을 서버의 $ CATALINA_BASE/conf/context로 이동해야했습니다. xml 폴더. 훌륭한 솔루션은 아니지만 작동합니다.

+0

webapp를 다시 배포하거나 해당 폴더에 직접 적용하지 않는 한 context.xml의 업데이트는 $ CATALINA_BASE/conf/context.xml에서 적용되지 않습니다. – EJP

+0

감사합니다. 이 문제의 원인을 사냥한지 6 시간이 지난 후에도 솔루션이 작동합니다. – Hafnernuss

2

같이, 하나 개의 솔루션은 $ CATALINA_BASE/conf의/context.xml에로 항목을 이동하는 것입니다 위의 대답

또 다른 방법은 여기에 설명되어 있습니다 : 특히 http://blogs.agilefaqs.com/2009/11/23/cannot-create-jdbc-driver-of-class-for-connect-url-null/

"고의 context.xml 파일을 복사 tomcat/conf/Catalina/localhost 폴더로 이동하여 <web_app_name>.xml으로 이름을 바꿉니다. "

파일 접근 권한 문제로 인해"tomcat이 실행중인 사용자에게이 폴더에 쓸 수있는 권한이 없습니다. 그래서 우리는 그룹 소유주를 바꿨다. p of tomcat 및/etc/tomcat 폴더를 tomcat 사용자가 속한 그룹과 동일한 그룹에 추가하면 마술처럼 이전과 같이 모든 작업이 시작됩니다. "

이 솔루션은 데이터베이스 연결 속성을 포함하여 전체 웹 응용 프로그램을 .war 파일로 묶어 둘 수 있기 때문에 나에게 '깨끗해'보인다.

3

동일한 문제가 발생하여 context.xml의 <Resource> 이름 선언이 web.xml의 <resource-ref> name에 정의 된 것과 일치하지 않는 것으로 나타났습니다.

관련 문제