如何使用 Mulesoft 4 为 postgresql 找到合适的驱动程序
How to find suitable driver for postgresql using Mulesoft 4
我设置了从 Anypoint Studio 7.4 到数据库的连接,并且我使用的是 postgresql 版本 42.2.1。
这是我的数据库配置:
错误响应:
org.mule.runtime.api.connection.ConnectionException: Could not obtain connection from data source
Caused by: org.mule.extension.db.api.exception.connection.ConnectionCreationException: Could not obtain connection from data source
Caused by: org.mule.runtime.extension.api.exception.ModuleException: java.sql.SQLException: Cannot get connection for URL jdbc:postgresql://myhost:port/mulesoft : No suitable driver found for jdbc:postgresql:myhost:port/mulesoft
Caused by: java.sql.SQLException: Cannot get connection for URL jdbc:postgresql:myhost:port/mulesoft : No suitable driver found for jdbc:postgresql:myhost:port/mulesoft
at org.mule.extension.db.internal.domain.connection.JdbcConnectionFactory.createConnection(JdbcConnectionFactory.java:57)
at org.mule.extension.db.internal.domain.connection.DbConnectionProvider.connect(DbConnectionProvider.java:139)
at org.mule.extension.db.internal.domain.connection.DbConnectionProvider.connect(DbConnectionProvider.java:71)
您需要使用配置按钮或手动将 Postgresql JDBC 驱动程序依赖项添加到 pom。
示例 pom:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.9</version>
</dependency>
您还需要将驱动程序 groupId 和 artifactId 添加到 pom 中的 Mule Maven 插件的共享库部分,以便它可以被 DB 连接器访问。
示例:
...
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
如果配置正确,请检查 URL 中是否存在数据库名称。比如JDBCURLjdbc:postgresql:myhost:port/mulesoft
,最后的/mulesoft
就是数据库名。如果缺少它,可能会导致同样的错误。
我设置了从 Anypoint Studio 7.4 到数据库的连接,并且我使用的是 postgresql 版本 42.2.1。
这是我的数据库配置:
错误响应:
org.mule.runtime.api.connection.ConnectionException: Could not obtain connection from data source
Caused by: org.mule.extension.db.api.exception.connection.ConnectionCreationException: Could not obtain connection from data source
Caused by: org.mule.runtime.extension.api.exception.ModuleException: java.sql.SQLException: Cannot get connection for URL jdbc:postgresql://myhost:port/mulesoft : No suitable driver found for jdbc:postgresql:myhost:port/mulesoft
Caused by: java.sql.SQLException: Cannot get connection for URL jdbc:postgresql:myhost:port/mulesoft : No suitable driver found for jdbc:postgresql:myhost:port/mulesoft
at org.mule.extension.db.internal.domain.connection.JdbcConnectionFactory.createConnection(JdbcConnectionFactory.java:57)
at org.mule.extension.db.internal.domain.connection.DbConnectionProvider.connect(DbConnectionProvider.java:139)
at org.mule.extension.db.internal.domain.connection.DbConnectionProvider.connect(DbConnectionProvider.java:71)
您需要使用配置按钮或手动将 Postgresql JDBC 驱动程序依赖项添加到 pom。
示例 pom:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.9</version>
</dependency>
您还需要将驱动程序 groupId 和 artifactId 添加到 pom 中的 Mule Maven 插件的共享库部分,以便它可以被 DB 连接器访问。
示例:
...
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>3.3.5</version>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
如果配置正确,请检查 URL 中是否存在数据库名称。比如JDBCURLjdbc:postgresql:myhost:port/mulesoft
,最后的/mulesoft
就是数据库名。如果缺少它,可能会导致同样的错误。