Skip to content
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

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

Open
zyro23 opened this issue Jun 15, 2024 · 1 comment
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@zyro23
Copy link

zyro23 commented Jun 15, 2024

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
zyro23 added a commit to zyro23/spring-data-commons-3108 that referenced this issue Jun 15, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 15, 2024
@quaff
Copy link
Contributor

quaff commented Jun 20, 2024

spring-projects/spring-boot#39797 is trying to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants