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

Support comma-separated values when resolving placeholders in @EntityScan's basePackages or value attributes #25415

Closed
reckart opened this issue Feb 25, 2021 · 7 comments
Assignees
Labels
status: reserved-for-conference-event status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@reckart
Copy link

reckart commented Feb 25, 2021

It does not seem to be possible in inject a multi-valued property into the @EntityScan annotation.

Examples that do not work:

application.properties
packages-to-scan=package1,package2

@EntityScan(basePackages = "${packages-to-scan}")
@EntityScan(basePackages = "#{'${packages-to-scan}'.split(',')}")

---

application.yml
packages-to-scan:
- package1
- package2

@EntityScan(basePackages = "${packages-to-scan}")
@EntityScan(basePackages = "#{'${packages-to-scan}'}")
@EntityScan(basePackages = "#{${packages-to-scan}.join(',')}")

Related unresolved question on Stack Overflow: https://stackoverflow.com/questions/55374224/reading-multiple-entity-scan-packages-in-spring-boot-application

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 25, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2021

@EntityScan does not support property resolution so the behaviour you have seen is expected. Having external control over the entities that are scanned is a rare use case so it isn't directly supported. Without knowing why you want to change the packages that are scanned via configuration, it's hard to advise on an alternative. You may be able to use a number of profile-specific classes each annotated with @EntityScan so that the packages can be controlled based on the active profile.

To avoid duplication of effort, I'm going to close this issue in favour of the question on Stack Overflow.

Edit: I see now that the Stack Overflow question is a couple of years old. If the answers to the question and the above do not help you, please ask a question of your own that explains why you want to externalize the packages to scan. That will make it easier for people to suggest an appropriate alternative.

@wilkinsona wilkinsona added for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 25, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2021

I was mistaken above. As shown by #25436, @EntityScan did support property resolution in 2.3 so, if we decide to reinstate support, we might want to consider how to handle multi-value properties.

@wilkinsona wilkinsona reopened this Feb 25, 2021
@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged and removed for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid labels Feb 25, 2021
@reckart
Copy link
Author

reckart commented Feb 25, 2021

It would be great if the same solution could be applied also to other annotations related to package scanning such as @AutoConfigurationPackage and @ComponentScan.

@mbhave
Copy link
Contributor

mbhave commented Mar 1, 2021

@reckart As Andy mentioned, could you elaborate on why you want to change the packages based on configuration?

@reckart
Copy link
Author

reckart commented Mar 1, 2021

I am maintaining an application where we normally restrict the package scanning to packages that we ship. However, as part of allowing users to supply plugins, I thought it would be useful if the users could re-configure the package scanning to allow the packages from their plugins to be scanned as well. Mind, a better plugin mechanism might also resolve that - but for a poor-mans plugin approach where people can simply throw in a few new JARs without having to recompile the entire thing, it would come in quite handy if they could extend the package scanning scope without having to recompile the main application.

@mbhave
Copy link
Contributor

mbhave commented Mar 1, 2021

Thanks for the context.

It looks like @ComponentScan supports placeholder resolution with comma-separated values.

I think in that case it would make sense to reinstate the behavior in #25436 so that it aligns with component scanning and also handle multiple values.

@wilkinsona wilkinsona changed the title EntityScan annotation does not work with multi-valued properties and related observations Support comma-separated values when resolving placeholders in @EntityScan's basePackages or value attributes Mar 8, 2021
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 8, 2021
@wilkinsona wilkinsona added this to the 2.x milestone Mar 8, 2021
saraswathy-krish added a commit to saraswathy-krish/spring-boot that referenced this issue Jul 15, 2021
Update EntityScanPAckages to support comma-separated values when resolving placeholders in EntityScan's basePackages or value attributes.

Fixes spring-projectsgh-25415
@mbhave
Copy link
Contributor

mbhave commented Jul 15, 2021

Closing in favor of PR #27355.

@mbhave mbhave closed this as completed Jul 15, 2021
@mbhave mbhave removed this from the 2.x milestone Jul 15, 2021
@mbhave mbhave added the status: superseded An issue that has been superseded by another label Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: reserved-for-conference-event status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
5 participants