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);
}
@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.
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.
When removing the spring-boot-devtools dependency the error no longer occurs.
FWIW, I see the same failure both with and without DevTools.
This is an issue in Spring Data JDBC that is going to be addressed with DATAJDBC-437.
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.
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).
Most helpful comment
We've got
DATACMNS-1596andDATAJDBC-437fixed 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 settingspring-data-releasetrain.versionto eitherMoore-BUILD-SNAPSHOTorNeumann-BUILD-SNAPSHOT(prefer the former for better chance of compatibility).