我建立了从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)
您需要使用configure按钮或手动将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>