Skip to content

refactor(spring): promote @Configuration classes to @AutoConfiguration#24304

Open
heruan wants to merge 2 commits into
mainfrom
refactor/vaadin-spring-autoconfiguration
Open

refactor(spring): promote @Configuration classes to @AutoConfiguration#24304
heruan wants to merge 2 commits into
mainfrom
refactor/vaadin-spring-autoconfiguration

Conversation

@heruan
Copy link
Copy Markdown
Member

@heruan heruan commented May 8, 2026

Summary

The vaadin-spring module mixed @Configuration with the AutoConfiguration.imports registration mechanism, while two of the configs were pulled in transitively via @Import from SpringBootAutoConfiguration. This change promotes all four to @AutoConfiguration so each is registered through Spring Boot's auto-configuration mechanism and gets proxyBeanMethods=false.

Discovery before this change

  • META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports listed only SpringBootAutoConfiguration, SpringSecurityAutoConfiguration, VaadinScopesConfig.
  • VaadinApplicationConfiguration and VaadinServletConfiguration were brought in transitively via @Import from SpringBootAutoConfiguration.
  • No forced package scanning of com.vaadin.flow.* exists — VaadinScanPackagesRegistrar only records user-supplied scan packages for @Route discovery.
  • META-INF/spring.factories is used only for SpringApplicationRunListener / EnvironmentPostProcessor, not auto-configuration.

Changes

  • SpringBootAutoConfiguration: @Configuration + @AutoConfigureBefore(WebMvcAutoConfiguration.class)@AutoConfiguration(before = WebMvcAutoConfiguration.class). Dropped @Import of the two slices (now auto-registered independently).
  • VaadinScopesConfig: @Configuration@AutoConfiguration (all @Beans are static, so proxyBeanMethods=false is safe).
  • VaadinApplicationConfiguration: @Configuration@AutoConfiguration and added to AutoConfiguration.imports.
  • VaadinServletConfiguration: @Configuration@AutoConfiguration and added to AutoConfiguration.imports. vaadinRootMapping(...) now receives the forwarding Controller via injection instead of calling the bean method directly — this avoided creating a duplicate Controller instance under proxyBeanMethods=false.
  • DevModeHandlerStopTest: previously relied on the @Import chain to transitively load VaadinApplicationConfiguration (which contributes SpringApplicationContextInit). Now opts in explicitly via AutoConfigurations.of(...).

Backward compatibility

  • @EnableVaadin (used by non-Boot Spring users) keeps @Import-ing the four classes. @AutoConfiguration is meta-annotated with @Configuration, so @Import continues to work; auto-config ordering metadata is simply ignored when imported manually.
  • SpringSecurityAutoConfiguration was already @AutoConfiguration — untouched.
  • VaadinAwareSecurityContextHolderStrategyConfiguration is @Deprecated/no-op — untouched.

Test plan

  • mvn test -pl :vaadin-spring — 436 tests pass, 0 failures, 1 pre-existing skip
  • mvn spotless:check -pl :vaadin-spring — clean
  • Reviewer: verify Spring Boot apps still bootstrap and that @EnableVaadin still works for non-Boot Spring usage
  • Reviewer: confirm AOT/native image paths (no impact expected — springnative AOT processors remain registered as static beans of SpringBootAutoConfiguration)

🤖 Marked as draft per local convention. Please review and mark ready when satisfied.

The vaadin-spring module mixed Configuration with the
AutoConfiguration.imports registration mechanism, while two of the
configs were pulled in transitively via Import from
SpringBootAutoConfiguration. Promote all four to AutoConfiguration so
each config is registered through Spring Boot's auto-configuration
mechanism and gets proxyBeanMethods=false:

- SpringBootAutoConfiguration: Configuration + AutoConfigureBefore ->
  AutoConfiguration(before = WebMvcAutoConfiguration.class); Import of
  the two slices removed (they're now auto-registered independently)
- VaadinScopesConfig: Configuration -> AutoConfiguration (all Beans are
  static, so proxyBeanMethods=false is safe)
- VaadinApplicationConfiguration: Configuration -> AutoConfiguration
  and added to AutoConfiguration.imports
- VaadinServletConfiguration: Configuration -> AutoConfiguration and
  added to AutoConfiguration.imports; vaadinRootMapping() now receives
  the forwarding Controller via injection instead of calling the bean
  method directly, which would have produced a duplicate Controller
  under proxyBeanMethods=false

EnableVaadin still imports the four classes for non-Boot users -
AutoConfiguration is meta-annotated with Configuration so Import keeps
working; the auto-config ordering metadata is simply ignored when a
class is imported manually.

DevModeHandlerStopTest used to rely on the old Import chain to
transitively load VaadinApplicationConfiguration (which contributes
SpringApplicationContextInit); it now lists that auto-config explicitly
in AutoConfigurations.of(...).
@heruan heruan force-pushed the refactor/vaadin-spring-autoconfiguration branch from d339b3c to 4bb6ad2 Compare May 8, 2026 12:54
@heruan heruan self-assigned this May 8, 2026
@heruan heruan marked this pull request as ready for review May 8, 2026 12:55
@github-actions github-actions Bot added the +1.0.0 label May 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Test Results

 1 404 files  ±0   1 404 suites  ±0   1h 21m 12s ⏱️ -30s
10 128 tests ±0  10 058 ✅ ±0  70 💤 ±0  0 ❌ ±0 
10 603 runs  ±0  10 524 ✅ ±0  79 💤 ±0  0 ❌ ±0 

Results for commit bb61fe5. ± Comparison against base commit eca39c2.

♻️ This comment has been updated with latest results.

…ation

VaadinServletConfiguration and VaadinApplicationConfiguration used to be
Import-ed by SpringBootAutoConfiguration, which carried
AutoConfigureBefore(WebMvcAutoConfiguration.class). After they were
promoted to independent AutoConfigurations they lost that ordering hint
and could be processed after WebMvcAutoConfiguration, leaving
RootExcludeHandler (the HandlerMapping that forwards / to VaadinServlet)
registered too late relative to WebMvc's own mappings.

The result was 404 on every Vaadin route (e.g. /, /my/login/page) in
Spring Boot apps that pull WebMvcAutoConfiguration in, which broke the
test-spring-security-flow ITs in flow-tests/vaadin-spring-tests/.
test-spring kept passing because it uses plain Spring MVC via
WebMvcConfigurationSupport rather than the auto-configuration path.

Restore the original ordering by annotating both classes with
AutoConfiguration(before = WebMvcAutoConfiguration.class).
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🔎Iteration reviews

Development

Successfully merging this pull request may close these issues.

1 participant