-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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 a configuration property for Spring Data Web's serialization mode #39797
Conversation
Please hold on until Spring Data Bom 2024.0.0 released. |
...e/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java
Show resolved
Hide resolved
@@ -79,4 +82,10 @@ public SortHandlerMethodArgumentResolverCustomizer sortCustomizer() { | |||
return (resolver) -> resolver.setSortParameter(this.properties.getSort().getSortParameter()); | |||
} | |||
|
|||
@Primary // override bean created by @EnableSpringDataWebSupport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should provide a better way to do this, perhaps requiring a change in Spring Data, as I'd prefer not to have multiple beans of the same type in the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odrotbohm I have a vague recollection that we've already discussed this but I haven't been able to find it.
I guess we could use @ConditionalOnProperty
to either auto-configure @EnableSpringDataWebSupport
or @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
. I'm a little hesitant as this approach won't scale as more attributes are added but it would work for now I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ultimately want to nudge people into using VIA_DTO
at some point, as that's the better way of serializing Page
instances by default. We kept the default at DIRECT
for 2024.0.0 to not force applications into the new model, potentially causing them to break their APIs and thus not upgrading. That said, if the Boot team was fine with such a change, we could of course already flip the default, with the users being able to re-instantiate the old behavior by explicitly adding @EnableSpringDataWebSupport(pageSerializationMode = DIRECT)
to their application.
Adding a configuration property to flip that switch might be nice, but at the same time, I wonder whether having to use the annotation isn't just enough? On the other hand, I can see this being a nice completion of the spring.data.web.pageable.…
property namespace.
Different auto-configurations based on the property look good to me. We have no plans to extend to different rendering strategies, as ultimately, we'd like users to use Spring HATEOAS to properly create standardized response types that support linking when rendering Page
instances. Thus, the enum is more of a flag to opt either into a safer way of serializing those (current model), or opt into the legacy way should we decide to flip the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ConditionalOnProperty
is not appropriate here, It's just a flag that should be stick to other pageable settings as possible, not like spring.data.redis.client-type
which affect creation of other beans.
I'd prefer to not register SpringDataWebSettings
bean if pageSerializationMode
is default as SpringDataWebAutoConfiguration
did, then the @Primary
could be removed, here is my proposal: spring-projects/spring-data-commons#3054
…ault allow application to register their own SpringDataWebSettings without @primary see spring-projects/spring-boot#39797 (comment)
I labelled this as blocked but neglected to say why. We're waiting for the outcome of spring-projects/spring-data-commons#3054. |
It could be that I am missing something here, but the presence of a It feels a bit weird to, if the annotation is configured, not forward its configuration default value into downstream configuration setup. That extending into having to write that latter code re-implementing a default that's already set and conveyed through the annotation attribute's value. |
Thanks, @odrotbohm.
As things stand, if you use the annotation, you'll lose our customization of paging and sorting.
We already use @Configuration(proxyBeanMethods = false)
@EnableSpringDataWebSupport
@ConditionalOnProperty(name = "spring.data.web.pageable.serialization-mode", havingValue = "direct",
matchIfMissing = true)
class EnableSpringDataWebSupportConfiguration {
}
@Configuration(proxyBeanMethods = false)
@EnableSpringDataWebSupport(pageSerializationMode = PageSerializationMode.VIA_DTO)
@ConditionalOnProperty(name = "spring.data.web.pageable.serialization-mode", havingValue = "via-dto",
matchIfMissing = false)
class EnableCustomizedSpringDataWebSupportConfiguration {
} spring-projects/spring-data-commons#3054 would remove the need for this little bit of complexity in Boot. |
@odrotbohm could you please review the comment above when you get a chance? Thanks! |
We now refrain from registering a SpringDataWebSettings instance as bean in the ApplicationContext if @EnableSpringDataWebSupport is used without an explicit declaration of pageSerializationMode. This allows Spring Boot to use the annotation, but allow the attribute value to be configured via a property at the same time. See spring-projects/spring-boot#39797 (comment) for details. Fixes GH-3054.
We now refrain from registering a SpringDataWebSettings instance as bean in the ApplicationContext if @EnableSpringDataWebSupport is used without an explicit declaration of pageSerializationMode. This allows Spring Boot to use the annotation, but allow the attribute value to be configured via a property at the same time. See spring-projects/spring-boot#39797 (comment) for details. Fixes GH-3054.
I'm sorry this took so long to get to. I've merged @quaff's contribution and ported it back into the 3.3.x branch. We now do not register a |
|
...boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
Outdated
Show resolved
Hide resolved
...ain/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java
Show resolved
Hide resolved
Thank you, @quaff. |
loading the application context fails under spring boot 3.4.0-M3 due to a `NoUniqueBeanDefinitionException` caused by there being 2 `SpringDataWebSettings` beans available during bean dependency resolution. This might be related to the changes made in spring-projects/spring-boot#39797 Anyway, adding the `@EnableSpringDataWebSupport` annotation fixes the problem.
We now refrain from registering a SpringDataWebSettings instance as bean in the ApplicationContext if @EnableSpringDataWebSupport is used without an explicit declaration of pageSerializationMode. This allows Spring Boot to use the annotation, but allow the attribute value to be configured via a property at the same time. See spring-projects/spring-boot#39797 (comment) for details. Fixes spring-projectsGH-3054.
…configuration metadata See spring-projectsgh-39797
* build(deps): bump the spring-boot group with 5 updates Bumps the spring-boot group with 5 updates: | Package | From | To | | --- | --- | --- | | [org.springframework.boot:spring-boot-starter-tomcat](https://github.com/spring-projects/spring-boot) | `3.4.0-M2` | `3.4.0-M3` | | [org.springframework.boot:spring-boot-autoconfigure](https://github.com/spring-projects/spring-boot) | `3.4.0-M2` | `3.4.0-M3` | | [org.springframework.boot:spring-boot-starter-logging](https://github.com/spring-projects/spring-boot) | `3.4.0-M2` | `3.4.0-M3` | | [org.springframework.boot:spring-boot-starter-test](https://github.com/spring-projects/spring-boot) | `3.4.0-M2` | `3.4.0-M3` | | [org.springframework.boot](https://github.com/spring-projects/spring-boot) | `3.4.0-M2` | `3.4.0-M3` | Updates `org.springframework.boot:spring-boot-starter-tomcat` from 3.4.0-M2 to 3.4.0-M3 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v3.4.0-M2...v3.4.0-M3) Updates `org.springframework.boot:spring-boot-autoconfigure` from 3.4.0-M2 to 3.4.0-M3 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v3.4.0-M2...v3.4.0-M3) Updates `org.springframework.boot:spring-boot-starter-logging` from 3.4.0-M2 to 3.4.0-M3 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v3.4.0-M2...v3.4.0-M3) Updates `org.springframework.boot:spring-boot-starter-test` from 3.4.0-M2 to 3.4.0-M3 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v3.4.0-M2...v3.4.0-M3) Updates `org.springframework.boot` from 3.4.0-M2 to 3.4.0-M3 - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v3.4.0-M2...v3.4.0-M3) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-tomcat dependency-type: direct:production update-type: version-update:semver-patch dependency-group: spring-boot - dependency-name: org.springframework.boot:spring-boot-autoconfigure dependency-type: direct:production update-type: version-update:semver-patch dependency-group: spring-boot - dependency-name: org.springframework.boot:spring-boot-starter-logging dependency-type: direct:production update-type: version-update:semver-patch dependency-group: spring-boot - dependency-name: org.springframework.boot:spring-boot-starter-test dependency-type: direct:production update-type: version-update:semver-patch dependency-group: spring-boot - dependency-name: org.springframework.boot dependency-type: direct:production update-type: version-update:semver-patch dependency-group: spring-boot ... Signed-off-by: dependabot[bot] <support@github.com> * fix spring data web support autoconfiguration loading the application context fails under spring boot 3.4.0-M3 due to a `NoUniqueBeanDefinitionException` caused by there being 2 `SpringDataWebSettings` beans available during bean dependency resolution. This might be related to the changes made in spring-projects/spring-boot#39797 Anyway, adding the `@EnableSpringDataWebSupport` annotation fixes the problem. * ci: add java 23 to test matrix --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JKatzwinkel <JKatzwinkel@users.noreply.github.com>
see spring-projects/spring-data-commons@5dd7b32