I am trying hard to inject the default datasource but I have the following error:
javax.enterprise.inject.IllegalProductException: Normal scoped producer method may not return null: io.quarkus.agroal.runtime.DataSourceProducer.createDefaultDataSource()
This is my current situation:
application.properties
quarkus.datasource.driver = com.mysql.cj.jdbc.Driver
quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3307/sandbox
quarkus.datasource.username=root
quarkus.datasource.password=password
quarkus.datasource.jdbc.min-size=0
quarkus.datasource.jdbc.max-size=11
MyClass.java
@ApplicationScoped
public class MyClass {
@Inject
AgroalDataSource dataSource;
void methodUsingDataSource() {...}
}
However I made it works with a named datasource with the SAME configuration as the default one:
application.properties
quarkus.datasource.users.driver = com.mysql.cj.jdbc.Driver
quarkus.datasource.users.url=jdbc:mysql://localhost:3307/sandbox
quarkus.datasource.users.username=root
quarkus.datasource.users.password=password
quarkus.datasource.users.min-size=0
quarkus.datasource.users.max-size=11
MyClass.java
@ApplicationScoped
public class MyClass {
@Inject
@DataSource("users")
AgroalDataSource dataSource;
void methodUsingDataSource() {...}
}
Do you have any idea about how to fix this behaviour? This causes me issues when I want to setup Hibernate.
Remove this line:
quarkus.datasource.driver = com.mysql.cj.jdbc.Driver
and use this instead:
quarkus.datasource.db-kind = mysql
You're mixing deprecated and new configuration properties in the default datasource and your combination of it doesn't work.
The example you gave with the named datasource is only using the old configuration properties so it works OK.
Now I need to understand why you didn't have a proper error message. I'll go work on improving that.