Skip to content

Failure analysis description for BeanDefinitionOverrideExceptions includes useless information when a bean definition has no resource description #18721

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

Closed
mfol opened this issue Oct 24, 2019 · 6 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@mfol
Copy link

mfol commented Oct 24, 2019

Hello, I come to report that the following bug can be reproduced (Spring Boot 2.2.0.RELEASE):

1 - Use the dependencies:
  spring-boot-starter-data-jdbc, spring-boot-starter-data-jpa, spring-boot-starter-web, spring-boot-devtools, mysql-connector-java, lombok, spring-boot-starter-test, junit-vintage-engine

2 - Create a repository interface and extending entity JpaRepository

3 - Following error is displayed when starting the spring application using Spring Tool Suite 4:
          The bean 'personRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

4 - When removing the spring-boot-devtools dependency the error no longer occurs.

5 - When starting the spring application with the spring-boot-devtools dependency it is possible to verify that the application's Main method is invoked twice.

6 - Example:
public static void main (String [] args) { System.out.println ("test"); SpringApplication.run (XXXApplication.class, args); }

example.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 24, 2019
@philwebb
Copy link
Member

@fabiomilson Thanks for the report. The root cause of the error is the fact that two Spring Data projects are active and both are trying to implement the PersonRepository.

I assume you just want JPA so you can remove the following lines from your pom.xml:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

The error message is quite unhelpful, so I'll leave this issue open to see if we can improve that.

@philwebb philwebb changed the title The bean 'anyRepository', defined in null Misleading bean overriding exception is thrown when multiple Spring Data projects are active Oct 24, 2019
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 24, 2019
@philwebb philwebb added this to the 2.1.x milestone Oct 24, 2019
@wilkinsona
Copy link
Member

wilkinsona commented Oct 24, 2019

I think the root cause of this is a bug in Spring Data. It should enter strict mode when multiple stores are detected. In strict mode, Spring Data JPA alone would handle PersonRepository.

We should still improve the error message. The mentions of null add nothing.

@wilkinsona
Copy link
Member

When removing the spring-boot-devtools dependency the error no longer occurs.

FWIW, I see the same failure both with and without DevTools.

@mp911de
Copy link
Member

mp911de commented Oct 24, 2019

This is an issue in Spring Data JDBC that is going to be addressed with DATAJDBC-437.

@wilkinsona
Copy link
Member

Here's the failure analysis that we should improve:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'personRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

"defined in null" is appearing because the bean definition has a null resource description but it doesn't add anything. We should change the description when one or both of the definitions has a null resource description.

@wilkinsona wilkinsona changed the title Misleading bean overriding exception is thrown when multiple Spring Data projects are active Failure analysis description for BeanDefinitionOverrideExceptions includes useless information when a bean definition has no resource description Oct 24, 2019
@wilkinsona wilkinsona added type: bug A general bug and removed type: enhancement A general enhancement labels Oct 24, 2019
odrotbohm added a commit to spring-projects/spring-data-commons that referenced this issue Oct 24, 2019
…laim repository interfaces anymore.

Previously, a module not exposing any entity identifying annotations would have claimed a repository definition and potentially overrode the bean definition of another store that was the proper claim in the first place. We have now changed this to abstain from a claim of the interface.

We' also tweaked the log output in the following cases:

1. If the module neither returns an identifying type nor entity identifying annotations, we now log a warning that a module does not support a multi-module setup and answer all assignment requests with false.

2. The info level warning indicating an interface has been dropped now reports which annotations or interface base types to use.

Related tickets: spring-projects/spring-boot#18721
odrotbohm added a commit to spring-projects/spring-data-commons that referenced this issue Oct 24, 2019
…laim repository interfaces anymore.

Previously, a module not exposing any entity identifying annotations would have claimed a repository definition and potentially overrode the bean definition of another store that was the proper claim in the first place. We have now changed this to abstain from a claim of the interface.

We' also tweaked the log output in the following cases:

1. If the module neither returns an identifying type nor entity identifying annotations, we now log a warning that a module does not support a multi-module setup and answer all assignment requests with false.

2. The info level warning indicating an interface has been dropped now reports which annotations or interface base types to use.

Original pull request: #411.
Related tickets: spring-projects/spring-boot#18721
mp911de pushed a commit to spring-projects/spring-data-commons that referenced this issue Oct 24, 2019
…laim repository interfaces anymore.

Previously, a module not exposing any entity identifying annotations would have claimed a repository definition and potentially overrode the bean definition of another store that was the proper claim in the first place. We have now changed this to abstain from a claim of the interface.

We' also tweaked the log output in the following cases:

1. If the module neither returns an identifying type nor entity identifying annotations, we now log a warning that a module does not support a multi-module setup and answer all assignment requests with false.

2. The info level warning indicating an interface has been dropped now reports which annotations or interface base types to use.

Original pull request: #411.
Related tickets: spring-projects/spring-boot#18721
mp911de pushed a commit to spring-projects/spring-data-commons that referenced this issue Oct 24, 2019
…laim repository interfaces anymore.

Previously, a module not exposing any entity identifying annotations would have claimed a repository definition and potentially overrode the bean definition of another store that was the proper claim in the first place. We have now changed this to abstain from a claim of the interface.

We' also tweaked the log output in the following cases:

1. If the module neither returns an identifying type nor entity identifying annotations, we now log a warning that a module does not support a multi-module setup and answer all assignment requests with false.

2. The info level warning indicating an interface has been dropped now reports which annotations or interface base types to use.

Original pull request: #411.
Related tickets: spring-projects/spring-boot#18721
mp911de pushed a commit to spring-projects/spring-data-commons that referenced this issue Oct 24, 2019
…laim repository interfaces anymore.

Previously, a module not exposing any entity identifying annotations would have claimed a repository definition and potentially overrode the bean definition of another store that was the proper claim in the first place. We have now changed this to abstain from a claim of the interface.

We' also tweaked the log output in the following cases:

1. If the module neither returns an identifying type nor entity identifying annotations, we now log a warning that a module does not support a multi-module setup and answer all assignment requests with false.

2. The info level warning indicating an interface has been dropped now reports which annotations or interface base types to use.

Original pull request: #411.
Related tickets: spring-projects/spring-boot#18721
@odrotbohm
Copy link
Member

We've got DATACMNS-1596 and DATAJDBC-437 fixed and ready for the Spring Data service release that will make it into Spring Boot 2.2.1. Feel free to give the snapshots a try by setting spring-data-releasetrain.version to either Moore-BUILD-SNAPSHOT or Neumann-BUILD-SNAPSHOT (prefer the former for better chance of compatibility).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants