2016-10-19 28 views
-1

Tomcat 7サーバーに2つのSpring Rooアプリケーションをデプロイしました。私は例外接続URL postgres:// username:password @ localhost:5432/dbnameのJDBCドライバを作成できません

Cannot create JDBC driver of class 'org.postgresql.Driver' for connect URL 'postgres://username:[email protected]:5432/db' 
java.sql.SQLException: No suitable driver 
    at java.sql.DriverManager.getDriver(DriverManager.java:278) 
    at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437) 
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) 
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279) 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) 

の下に取得していたアプリケーションのサービスデータベースの基本構成の下

アプリケーション1

アプリケーションのcontext.xml

を見つけてください。
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> 
    <property name="driverClassName" value="${database.driverClassName}"/> 
    <property name="url" value="${database.url}"/> 
    <property name="username" value="${database.username}"/> 
    <property name="password" value="${database.password}"/> 
    <property name="testOnBorrow" value="true"/> 
    <property name="testOnReturn" value="true"/> 
    <property name="testWhileIdle" value="true"/> 
    <property name="timeBetweenEvictionRunsMillis" value="1800000"/> 
    <property name="numTestsPerEvictionRun" value="3"/> 
    <property name="minEvictableIdleTimeMillis" value="1800000"/> 
    <property name="validationQuery" value="SELECT version();"/> 
</bean> 
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
</bean> 
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/> 
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> 
    <property name="persistenceUnitName" value="persistenceUnit"/> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 

アプリケーション1. Database.properties

database.driverClassName=org.postgresql.Driver 
database.url=jdbc\:postgresql\://localhost\:5432/db 
database.username=username 
database.password=password 

アプリケーション2

アプリケーションのcontext.xml

<bean class="java.net.URI" id="dbUrl"> 
    <constructor-arg value="postgres://username:[email protected]:5432/db"/> 
</bean> 
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> 
    <property name="driverClassName" value="org.postgresql.Driver"/> 
    <property name="url" value="#{ 'jdbc:postgresql://' + @dbUrl.getHost() + ':' + @dbUrl.getPort() + @dbUrl.getPath() }"/> 
    <property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }"/> 
    <property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }"/> 
    <property name="testOnBorrow" value="true"/> 
    <property name="testOnReturn" value="true"/> 
    <property name="testWhileIdle" value="true"/> 
    <property name="timeBetweenEvictionRunsMillis" value="1800000"/> 
    <property name="numTestsPerEvictionRun" value="3"/> 
    <property name="minEvictableIdleTimeMillis" value="1800000"/> 
    <property name="validationQuery" value="SELECT version();"/> 
</bean> 
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
</bean> 
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/> 
<util:properties id="regex.properties" location="classpath:META-INF/spring/regex.properties"/> 
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> 
    <property name="persistenceUnitName" value="persistenceUnit"/> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 

私は私の問題を解決する方法をアドバイスしてください。..

+0

あなたの質問にある接続URLを見てください。 – Kayaman

+0

あなたのクラスパスにはpostgresライブラリがありますか? – f1sh

+0

はい、f1sh、私のアプリケーション2(古い)はデータベースと接続することができますが、1番目は – Mayur

答えて

2
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  destroy-method="close"> 
    <property name="driverClass" value="org.postgresql.Driver" /> 
    <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/db" /> 
    <property name="user" value="user" /> 
    <property name="password" value="pass" /> 
    <!-- pool sizing --> 
    <property name="initialPoolSize" value="3" /> 
    <property name="minPoolSize" value="6" /> 
    <property name="maxPoolSize" value="25" /> 
    <property name="acquireIncrement" value="3" /> 
    <property name="maxStatements" value="0" /> 
</bean> 

私はこれを使用して動作します

+0

正確に。接続URLが適切な形式になっていれば動作します。 – Kayaman

+0

@Kayaman URLは問題ありません編集しました – Mayur

+0

@Mayurあなたはどこで編集しましたか?私が見ているすべての場所でまだ間違っています。 – Kayaman

関連する問題