Confusing error message if using @Repository in a JDBC project
Expected Behavior
The error should say something like:
Cannot use a repository annotated with @Repository in a JDBC project, please use @JdbcRepository(dialect = ...) instead.
Actual Behaviour
The Micronaut Data docs are a bit confusing w.r.t. how to annotate repository interfaces. The docs start by saying (under "shared concepts") that you have to annotate them with @Repository which makes sense, but in fact if you use JDBC directly (no JPA/Hibernate) the repository must be annotated with @JdbcRepository. This is explained later but it's easy to miss and if you do, you get an exception with a message like this:
No backing RepositoryOperations configured for repository. Check your configuration and try again
This is pretty confusing. The problem isn't in the app config file, it's not clear what a "backing RepositoryOperations" is or why none is configured, and the generic "check your configuration and try again" advice is so vague it's nearly non-actionable.
Steps To Reproduce
- Set up a JDBC only Micronaut Data project.
- Write a repository that inherits from e.g.
GenericRepositoryand is annotated using@Repository - Run the app.
- Be puzzled by the resulting message.
Environment Information
No response
Example Application
No response
Version
4.4.4
Current error is:
Failed to inject value for parameter [jdbcOperations] of class: io.micronaut.data.jdbc.h2.H2PersonRepository$Intercepted
Message: No bean of type [io.micronaut.data.jdbc.runtime.JdbcOperations] exists.
* [JdbcOperations] requires the presence of a bean of type [javax.sql.DataSource].
* [DataSource] requires the presence of a bean of type [io.micronaut.configuration.jdbc.tomcat.DatasourceConfiguration].
* [DatasourceConfiguration] is disabled because:
- Configuration requires entries under the prefix: [datasources.default]
What is displayed for you?
I think the error message I see requires a data source to be configured.
The error you see would IMHO be easier to read with an alternate layout that puts the action item first, maybe like this:
Configuration requires entries under the prefix: datasources.default
therefore
... DatasourceConfiguration is disabled because:
... DataSource requires the presence of a bean of type io.micronaut.configuration.jdbc.tomcat.DatasourceConfiguration
... JdbcOperations requires the presence of a bean of type javax.sql.DataSource
... No bean of type io.micronaut.data.jdbc.runtime.JdbcOperations exists.
... Failed to inject value for parameter jdbcOperations of class: io.micronaut.data.jdbc.h2.H2PersonRepository$Intercepted
This layout is probably less intimidating especially to new devs because the thing they have to do comes up front, and chain of implications (which doesn't really matter in this case) comes afterwards where they are less likely to read.