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

Wildcard JPA packages are not scanned [SPR-16152] #20700

Closed
spring-projects-issues opened this issue Nov 2, 2017 · 5 comments
Closed

Wildcard JPA packages are not scanned [SPR-16152] #20700

spring-projects-issues opened this issue Nov 2, 2017 · 5 comments
Assignees
Labels
in: data type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 2, 2017

Petar Tahchiev opened SPR-16152 and commented

Looking at the latest 5.0.1 CandidateComponentIndexer code:

https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java#L68

candidates are filtered based on the startsWith criteria. This prevents packages containing wildcards to be scanned:

    @Bean(name = { "defaultEntityManagerFactory", "entityManagerFactory" })
    protected LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory(JpaProperties jpaProperties) throws PropertyVetoException, IOException {
        LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactory.setDataSource(defaultDataSource());
        entityManagerFactory.setJpaVendorAdapter(defaultJpaVendorAdapter());
        entityManagerFactory.setJpaProperties(defaultTestJpaProperties(jpaProperties));
        entityManagerFactory.setPackagesToScan("com.nemesis.platform.core.entity", "com.nemesis.platform.module.**.core.entity");
        entityManagerFactory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());

        return entityManagerFactory;
    }

Please note that this is a regression, as this used to work fine with 4.3.x


Affects: 5.0.1

Issue Links:

  • #20660 Spring context indexer does not work with nested classes

Referenced from: commits 9511d29, 1838ddb

1 votes, 4 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 2, 2017

Juergen Hoeller commented

I assume there is no regression in the classpath scanning, just a limitation in the indexer? This still worth addressing but not a regression in the usual sense.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 3, 2017

Stéphane Nicoll commented

I wasn't ware of that semantic of basePackage. Worth clarifying in the javadoc

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 7, 2017

Petar Tahchiev commented

I just tested and for me it's not 100% backward compatible. With spring 4.x this configuration:

entityManagerFactory.setPackagesToScan("com.nemesis.platform.core.entity", "com.nemesis.platform.module.**.core.entity");

would recognize entities in packages such as com.nemeiss.platform.module.search.core.entity.facet.MyEntity.

Now with spring 5.x I need to change my configuration to the following:

entityManagerFactory.setPackagesToScan("com.nemesis.platform.core.entity", "com.nemesis.platform.module.**.core.entity.**");

in order for those entities to be recognized.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 11, 2017

Vladimir Tsanev commented

I hit this too, and for me is a regression,

I do not want (cannot) know all the modules (they might be hundreds) that will be on my classpath so supporting wildcards for jpa entity and repositories is a must.

Using a PathMatcher instead of just startsWith in the indexer introduced with #16509 should not hurt performance much and is very handy when you rely on a naming convention in a project with a lot of modules.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 11, 2017

Vladimir Tsanev commented

I see that this is already resolved in 1838ddb#diff-82b81e59950da0e58fbd6b8f3ed25b99 sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data type: bug
Projects
None yet
Development

No branches or pull requests

2 participants