New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debug logging to help when a repository uses classes that are missing annotations #19373
Comments
Setup: @Repository
public interface ActionMovieRepository extends CrudRepository<ActionMovie, Long> {
} //Note the missing @Table
public class ActionMovie implements Movie {
@Id
private Long id;
//More fields and methods
} @Configuration
@EnableJdbcRepositories
@EnableTransactionManagement
public class JdbcDataConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().addScript("sql/tables.sql");
return builder.setType(EmbeddedDatabaseType.HSQL).build();
}
} Result:
However, the application fails startup with the cause of The reason is obvious once I found the log above, but it got lost in the rest of startup logs. Maybe it would be better to make this either a warning, or even fail startup when an incorrectly configured repository is found? |
The problem is that your starting point is not valid configuration. You have multiple store modules on the classpath and each of them is trying to identify the domain types it's supposed to manage. Neither your repository nor your domain type give any hints about this. In multi-store mode, each store module knows about a set of criterias it uses to identify the repository that it should handle. It now of course drops the ones it cannot properly identify as its own as other modules later in the bootstrap chain might claim it. So the JDBC module is basically telling you: I would've picked this up in single-module mode but as there are multiple store modules on the classpath, I do not claim this repository as there might be other modules whose assignment criterias this repository interfaces matches. That however is not something we want to pollute the log with All of that said, if you can think of better wording for the log message, I'll happily take suggestions. Also: maybe it's more an issue of consistently making sure we use the annotation in ever sample, the reference docs although not strictly necessary in less complex scenarios? |
I wonder if Spring Boot could do more if there was also a programmatic way to receive those events outside of just logging them. Perhaps then if the I imagine one reason that the log gets missed is because it's superseded by an actual exception. My initial instinct would be to start with the stacktrace, rather than to think about hunting backwards in the logs for other messages. |
It may be invalid now, but you're rather lulled into a false sense of security as there's no indication that it's invalid to begin with. If you start developing an app with only a single store on the classpath, the output looks like the following:
There's nothing here to indicate that there's a potential problem with the configuration and that it's valid only because there's a single store on the classpath. With a second store on the classpath, the following output is logged:
It feels like Spring Data has been too helpful in the first case and then not helpful enough in the second. To improve the second situation, I wonder if a diagnostic repository scanner could run after all of the real scanners. It could throw an exception describing anything that went unclaimed. Boot could perform some failure analysis of this exception so that it's presented to the user has helpfully as possible. I wonder if the first could be improved too. Perhaps a warning message could be logged to recommend the addition of a |
Care to elaborate? The log clearly states the change in configuration mode. The mentioned terms can clearly be found in the reference documentation describing the multi-store mode. The latter even describes the matching algorithm in elaborate detail. It then reports the offending repository and gives advice what to do to resolve the situation which matches what's described in the reference documentation. So what exactly is "lulling" people into a false sense of security here? As indicated above, the individual store modules cannot be more constraining at the point they're discovering the scenario as that would take other stores the opportunity to claim the repository interface. I am happy to explore means to resolve the situation that include means that exceed the scope of solely Spring Data. So far the problem hasn't really popped up at all or at least not reached the team. Phil's suggestions sound like a great idea I am happy to explore. That said, I think it's rather harsh to suggest we're acting with bad intentions and'd actively mislead users and make it hard for them to identify the root of the problem. |
In the first case, Spring Data has gone the extra mile and figured out that In the second case, I feel that the info messages aren't doing enough to help the user to figure out why something that worked with a single store has now stopped working when a second store was added. I suspect's that not because of their content, but because they're only logged at info level and are therefore easily missed. Phil suggested a reason for this above:
That sounds quite plausible to me.
That's why I was wondering if some sort of diagnostic scanner could run after all the proper stores have had a chance to claim all of the repository interfaces. It could then report on any that had gone unclaimed.
Sorry. I had no intention of suggesting that intentions were bad or that the current situation was due to a choice to mislead users. My intention was only to offer an opinion about why users may find the current behaviour hard to debug and to hopefully make some constructive suggestions about how it could be improved. |
See this Twitter discussion.
It would be nice if we could trigger additional debug/warning logs to help track down this kind of problem.
The text was updated successfully, but these errors were encountered: