Skip to content

entity basePackages in third-party jars #3461

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

Closed
en-o opened this issue May 6, 2024 · 2 comments
Closed

entity basePackages in third-party jars #3461

en-o opened this issue May 6, 2024 · 2 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@en-o
Copy link

en-o commented May 6, 2024

There exists JPA operations in a custom third-party JAR. If @EntityScan is used, it fails to load entities from the third-party JAR, resulting in a "Not a managed type" error. However, if @EntityScan is not used, JPA scanning in the business project will be ineffective. Upon debugging, I found that this is overridden in org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration#getPackagesToScan(). Currently, I need to append instead of override the entity scanning. I'm unsure if this is a bug or a design principle. My current approach to handling this is as follows:

Override the original class override method

protected String[] getPackagesToScan() {
List<String> packages = EntityScanPackages.get(this.beanFactory).getPackageNames();
if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) {
	packages = AutoConfigurationPackages.get(this.beanFactory);
	packages.add("cn.jdevelops.config.standalone.model");
}
return StringUtils.toStringArray(packages);
}

image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 6, 2024
@odrotbohm
Copy link
Member

This is a known issue with Spring Boot. Prefer to use @AutoConfigurationPackage to add multiple packages to the default entity scanning.

@odrotbohm odrotbohm added 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 May 6, 2024
@en-o
Copy link
Author

en-o commented May 6, 2024

This is a known issue with Spring Boot. Prefer to use @AutoConfigurationPackage to add multiple packages to the default entity scanning.

thanks

@en-o en-o closed this as completed May 6, 2024
@odrotbohm odrotbohm closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants