Skip to content

Make VaadinScanPackages serializable and merge scan packages correctly - #25062

Closed
Hariharan02112004 wants to merge 1 commit into
vaadin:mainfrom
Hariharan02112004:fix-enable-vaadin-multiple-scan-packages
Closed

Hariharan02112004 wants to merge 1 commit into
vaadin:mainfrom
Hariharan02112004:fix-enable-vaadin-multiple-scan-packages

Conversation

@Hariharan02112004

@Hariharan02112004 Hariharan02112004 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

This change extracts scan package handling into VaadinScanPackages and makes the class serializable.

Previously, scan package merging logic was handled inside VaadinScanPackagesRegistrar. The merge logic is now moved into VaadinScanPackages so that scan package handling remains in one place.

This also fixes serialization support required for VaadinScanPackages.

Fixes

Fixes #25022

Type of change

  • Bugfix

Checklist

  • I have read the contribution guide
  • I have added a description following the guideline
  • I have referenced the issue
  • I have added tests
  • New and existing tests are passing locally
  • I have performed self-review

@cla-assistant

cla-assistant Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Hariharan02112004

Copy link
Copy Markdown
Contributor Author

Updated description:

Description

This change extracts scan package handling into VaadinScanPackages and makes it Serializable.

Previously, scan package merging logic was handled inside VaadinScanPackagesRegistrar. The merge logic is now handled by VaadinScanPackages.

Fixes

Fixes #25022

@mcollovati mcollovati added the Contribution PRs coming from the community or external to the team label Jul 30, 2026
@mshabarov mshabarov moved this to 🔎Iteration reviews in Vaadin Flow | Hilla | Kits ongoing work Aug 12, 2026
@mshabarov mshabarov added Intent Approved Labeled open PR means 1. Problem confirmed, 2. Solution confirmed. and removed Intent Approved Labeled open PR means 1. Problem confirmed, 2. Solution confirmed. labels Sep 23, 2026
import java.util.Arrays;
import java.util.List;

public class VaadinScanPackages implements Serializable {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be turned into a Java record.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class becomes public, it requires proper Javadoc both at class, constructor and method level.
Javadoc should also state that it is an internal API.

  • For internal use only. May be renamed or removed in a future release.

We should consider if having it public makes sense (e.g. knowing user-defined packages are useful for some additional processor other than bootstrap) or if it can be package-private.


public VaadinScanPackages(String[] scanPackages) {
assert scanPackages != null;
this.scanPackages = new ArrayList<>(Arrays.asList(scanPackages));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.scanPackages could be an unmodifiable list. Consider using List.of(scanPackages)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if scanPackages can be a Set (or LinkedHashSet if order matters); duplicated packages are irrelevant.

return scanPackages;
}

public static String[] merge(String[] existingPackages,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add this method in this class. It's totally unrelated to class, it just concat two arrays.
I guess it can be moved to the caller class as a private helper method.

}

@Test
void vaadinScanPackagesIsSerializable() throws Exception {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be already covered by SpringClassesSerializableTest. We don't need to test serialization internals if we do not add any custom logic.

@mcollovati

Copy link
Copy Markdown
Collaborator

Thank you for this contribution, @Hariharan02112004! We continued the work in #26482, which includes your changes and the fixes from the review, with you as co-author. Closing this PR in favour of that one.

@mcollovati mcollovati closed this Oct 16, 2026
@github-project-automation github-project-automation Bot moved this from 🔎Iteration reviews to Done in Vaadin Flow | Hilla | Kits ongoing work Oct 16, 2026
mcollovati added a commit to javier-godoy/flow that referenced this pull request Oct 23, 2026
…26482)

Fixes vaadin#25022

**new feature** · vaadin-spring · Spring apps with `@EnableVaadin` on
more than one configuration class

Applications can now put `@EnableVaadin` with packages on several
configuration classes, for example one per module, and Vaadin scans the
packages of all of them. Before, a Spring Boot application failed at
startup with `BeanDefinitionOverrideException`, and plain Spring kept
only the packages of the last annotation.

**Risks:**
- ⚠️ Behaviour change: plain Spring applications with several
  `@EnableVaadin` annotations now scan all their packages, not only the
  packages of the last annotation processed
- ✅ No public API, security, memory, serialization, threading,
  performance or migration impact

- Changed `VaadinScanPackagesRegistrar` to add the packages of each
  `@EnableVaadin` to the bean definition that is already registered,
  instead of registering a second one
  - The packages keep their order and duplicates are removed
- Turned `VaadinScanPackages` into a package-private record that holds
  an unmodifiable list
- Documented in `EnableVaadin` that packages from several annotations
  are merged
- Added `VaadinScanPackagesRegistrarTest`, which runs with bean
  definition overriding disabled, as in Spring Boot
- Based on vaadin#25062 by @Hariharan02112004

---------

Co-authored-by: Hariharan G <167274701+Hariharan02112004@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution PRs coming from the community or external to the team

Projects

Development

Successfully merging this pull request may close these issues.

Allow multiple uses of the @EnableVaadin annotation.

3 participants