im new in Microprofile world and im trying to create a microservices using Open Liberty as implementation. The main problem here starts when im trying to connect to my database using MySql, and i cant find the reason. My server.xml file is the next one:
<library id="jdbcLib">
<fileset dir="jdbc" includes="*.jar"/>
</library>
<dataSource jndiName="jdbc/myDB">
<jdbcDriver libraryRef="jdbcLib"/>
<properties serverName="localhost" portNumber="3306"
databaseName="inventory"
user="root"
password="root"/>
</dataSource>
And my persistence.xml file is:
<persistence-unit name="jpa-unit" transaction-type="JTA">
<jta-data-source>jdbc/myDB</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
</persistence-unit>
I cant find what im doing wrong, but im getting the following exception:
java.sql.SQLNonTransientException: DSRA4000E: No implementations of [javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, javax.sql.XADataSource, java.sql.Driver] are found for dataSource[default-0] with library jdbcLib
Someone could help me out with this? i would be very grateful :D
It looks like you followed the example here: https://openliberty.io/docs/21.0.0.3/relational-database-connections-JDBC.html
Based on the exception, it looks like the driver jar isn't in the jdbc directory (which will be wlp/usr/server/server_name/jdbc) You should be able to get the version you need here: https://mvnrepository.com/artifact/mysql/mysql-connector-java
If you're using maven, you can use the Liberty Maven Plugin to download and copy the driver to the correct directory for you. Here's an example using the latest 8.0.26 driver:
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.3</version>
<configuration>
<copyDependencies>
<location>jdbc</location>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- You can omit the version below if you have
declared a dependency and want to simply use
that version, or specify the version as shown
if you don't include this artifact as a dependency. -->
<version>8.0.26</version>
</dependency>
</copyDependencies>
</configuration>
</plugin>