flow: Production build fails if Spring Boot Application implements AppShellConfigurator and is annotated with a Spring Data JPA Repository
Description of the bug
If the application class is used as AppShellConfigurator as in the starter project, the production build fails with NoClassDefFoundError: org/springframework/context/ApplicationEventPublisherAware if the application class is also annotated with @EnableJpaRepositories.
This happens only with profile production, but fails in the prepare-frontend goal that is executed before build-frontend.
The exception itself comes probably from the fact that the AppShellConfigurator class (or any class that is annotated with @Theme) is annotated with @EnableJpaRepository, which imports JpaRepositoryFactoryBean that ultimately implements ApplicationEventPublisherAware. However, why the class cannot be found is not not clear to me. Its dependency spring-context is included in the compile scope.
ApplicationEventPublisherAware has many implementations in Spring Security too.
More detailed stacktrace:
Caused by: java.lang.TypeNotPresentException: Type [unknown] not present at java.lang.reflect.Method.getDefaultValue (Method.java:724) at sun.reflect.annotation.AnnotationType.<init> (AnnotationType.java:133) at sun.reflect.annotation.AnnotationType.getInstance (AnnotationType.java:85) at sun.reflect.annotation.AnnotationParser.parseAnnotation2 (AnnotationParser.java:262) at sun.reflect.annotation.AnnotationParser.parseAnnotations2 (AnnotationParser.java:121) at sun.reflect.annotation.AnnotationParser.parseAnnotations (AnnotationParser.java:73) at java.lang.Class.createAnnotationData (Class.java:4068) at java.lang.Class.annotationData (Class.java:4057) at java.lang.Class.getAnnotationsByType (Class.java:3965) at com.vaadin.flow.internal.AnnotationReader.getAnnotationsFor (AnnotationReader.java:221) at com.vaadin.flow.server.frontend.scanner.FullDependenciesScanner.lambda$verifyTheme$5 (FullDependenciesScanner.java:383) at java.util.stream.ReferencePipeline$7$1.accept (ReferencePipeline.java:273) at java.util.Iterator.forEachRemaining (Iterator.java:133) at java.util.Spliterators$IteratorSpliterator.forEachRemaining (Spliterators.java:1845) at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509) at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:499) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:921) at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:682) at com.vaadin.flow.server.frontend.scanner.FullDependenciesScanner.verifyTheme (FullDependenciesScanner.java:389) at com.vaadin.flow.server.frontend.scanner.FullDependenciesScanner.discoverTheme (FullDependenciesScanner.java:339) at com.vaadin.flow.server.frontend.scanner.FullDependenciesScanner.<init> (FullDependenciesScanner.java:131) at com.vaadin.flow.server.frontend.scanner.FullDependenciesScanner.<init> (FullDependenciesScanner.java:94) at com.vaadin.flow.server.frontend.scanner.FrontendDependenciesScanner$FrontendDependenciesScannerFactory.createScanner (FrontendDependenciesScanner.java:93) at com.vaadin.flow.server.frontend.NodeTasks.<init> (NodeTasks.java:125) at com.vaadin.flow.plugin.base.BuildFrontendUtil.prepareFrontend (BuildFrontendUtil.java:172) at com.vaadin.flow.plugin.maven.PrepareFrontendMojo.execute (PrepareFrontendMojo.java:64) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:568) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationEventPublisherAware at java.lang.ClassLoader.defineClass1 (Native Method) at java.lang.ClassLoader.defineClass (ClassLoader.java:1012) at java.security.SecureClassLoader.defineClass (SecureClassLoader.java:150) at java.net.URLClassLoader.defineClass (URLClassLoader.java:524
Expected behavior
No exception during production build.
Minimal reproducible example
Using the starter:
- Include
spring-data-jpaas dependency - Implements a class implementing Repository, e.g.
public class TestRepository implements Repository<String, Integer>{}. Can be a static inner class of the Application class - Annotation Application with
@EnableJpaRepositories(basePackageClasses = Application.TestRepository.class)
Execute mvn clean package -Pproduction and see the build fail.
Versions
- Vaadin / Flow version: 24.4.3
- Java version: 17
- OS version: Windows
- Browser version (if applicable):
- Application Server (if applicable):
- IDE (if applicable):
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 23 (4 by maintainers)
Commits related to this issue
- chore: log class causing failure in frontend dependency scan Wraps the annotation finder function to log potential errors during class scanning and the class that originates the failure. References ... — committed to vaadin/flow by mcollovati 2 years ago
- chore: log class causing failure in frontend dependency scan Wraps the annotation finder function to log potential errors during class scanning and the class that originates the failure. References ... — committed to vaadin/flow by mcollovati 2 years ago
- chore: log class causing failure in frontend dependency scan (#19721) Wraps the annotation finder function to log potential errors during class scanning and the class that originates the failure. ... — committed to vaadin/flow by mcollovati 2 years ago
- chore: log class causing failure in frontend dependency scan (#19721) Wraps the annotation finder function to log potential errors during class scanning and the class that originates the failure. ... — committed to vaadin/flow by mcollovati 2 years ago
- chore: log class causing failure in frontend dependency scan (#19721) Wraps the annotation finder function to log potential errors during class scanning and the class that originates the failure. ... — committed to vaadin/flow by mcollovati 2 years ago
- chore: log class causing failure in frontend dependency scan (#19721) (#19724) Wraps the annotation finder function to log potential errors during class scanning and the class that originates the fa... — committed to vaadin/flow by vaadin-bot 2 years ago
- chore: log class causing failure in frontend dependency scan (#19721) (#19725) Wraps the annotation finder function to log potential errors during class scanning and the class that originates the fa... — committed to vaadin/flow by vaadin-bot 2 years ago
- fix: fix class and resource loading in maven plugin Introduces a custom class loader for ClassFinder to ensure resources and classes are loaded first from project dependencies and then from the plugi... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin Extracts logics from Flow mojos to separated task classes, loaded with a custom class loader composed by project and plugin dependencies, with the ... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taking precedence. This... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taking precedence. This... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin (#20465) * fix: fix class and resource loading in maven plugin Run Flow mojos using an isolated class loader that includes both project and plu... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin (#20465) Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taking precede... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin (#20465) Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taking precede... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin (#20465) (#20518) Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taki... — committed to vaadin/flow by mcollovati 2 years ago
- fix: fix class and resource loading in maven plugin (#20465) (#20519) Run Flow mojos using an isolated class loader that includes both project and plugin dependencies, with project dependencies taki... — committed to vaadin/flow by mcollovati 2 years ago
Moving @EnableJpaRepositories to another class with @Configuration worked for me as a workaround using 24.4.10 - but would be nice for there to be a proper fix for this given the impact.
It looks like that in 24.3 the class scan is not performed during
prepare-frontend, whereas it is done in 24.4. I have to check if this has been changed on purpose or if it is a regression caused by #19011Moving all Vaadin annotations to another class seems to work. Give the above snippet it would be like
and
Did you try my workaround, too?