spring-projects / spring-projects/spring-data-commons

using @EnableSpringDataWebSupport with spring-data-rest results in BeanDefinitionOverrideException

Open
#3,108 5 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jun 17, 2024.

status: waiting-for-triage
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

adding @EnableSpringDataWebSupport in a project that uses spring-boot-starter-data-rest results in a BeanDefinitionOverrideException preventing application startup.

context: i want to use PageSerializationMode.VIA_DTO. while that "just worked" by default with spring-data-commons 3.3.0, from 3.3.1 on we have to add @EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) explicitly (due to #3101).

sample app (boot-3.3.1-SNAPSHOT, spring-data-bom-2024.0.1-SNAPSHOT, spring-data-commons-3.3.1-SNAPSHOT at the time of writing) will be referenced asap.

2024-06-15T10:28:59.121+02:00  INFO 26728 --- [demo] [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 21.0.1 with PID 26728 [...]
2024-06-15T10:28:59.123+02:00  INFO 26728 --- [demo] [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2024-06-15T10:28:59.450+02:00  WARN 26728 --- [demo] [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'pageableResolver' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=pageableResolver; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]] for bean 'pageableResolver' since there is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguration; factoryMethodName=pageableResolver; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class]] bound.
2024-06-15T10:28:59.455+02:00  INFO 26728 --- [demo] [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-06-15T10:28:59.468+02:00 ERROR 26728 --- [demo] [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

The bean 'pageableResolver', defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/data/web/config/HateoasAwareSpringDataWebConfiguration.class] and overriding is disabled.

Action:

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.