Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

@EventListener annotations on @Configuration classes seems to fail compilation #1373

Closed
joshlong opened this issue Dec 12, 2021 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@joshlong
Copy link
Contributor

joshlong commented Dec 12, 2021

Hi, if I compile against Boot 2.6.1 and Spring Native 0.11 I encounter an error on compiling when using @EventListeners in a @Configuration class.

@Log4j2
@Configuration
public class IndexConfiguration {
  
  private final DateFormat dateFormat;
  
  IndexConfiguration(@IsoDateFormat DateFormat dateFormat) {
	  this.dateFormat = dateFormat;
  }
  
  @EventListener
  public void indexStarted(IndexingStartedEvent startedEvent) {
	  log.info("index build started " + this.dateFormat.format(startedEvent.getSource()));
  }
  
  @EventListener
  public void indexFinished(IndexingFinishedEvent finishedEvent) {
	  log.info("index build finished " + this.dateFormat.format(finishedEvent.getSource()));
  }
  
 // .. other @Bean definitions 

}

I get an error:

a.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
/Users/jlong/Drive/LIVE/joshlong-api/api/target/generated-sources/spring-aot/src/main/java/org/springframework/aot/ContextBootstrapInitializer.java:[8,31] cannot find symbol
  symbol:   class IndexConfiguration$$EnhancerBySpringCGLIB$$798cc92e
  location: package com.joshlong.blog.index

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1220)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:187)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo 
....

basically, the generated ContextBootstrapInitializer.java is trying to reference the proxied name of the @Configuration class (IndexConfiguration$$EnhancerBySpringCGLIB$$798cc92e), not IndexConfiguration itself.

If I move the @EventListener to a static nested @Component, everything works again:

@Log4j2
@Configuration
public class IndexConfiguration {

	@Component
	public static class Listener {

		private final DateFormat dateFormat;

		Listener(@IsoDateFormat DateFormat dateFormat) {
			this.dateFormat = dateFormat;
		}

		@EventListener
		public void indexStarted(IndexingStartedEvent startedEvent) {
			log.info("index build started " + this.dateFormat.format(startedEvent.getSource()));
		}

		@EventListener
		public void indexFinished(IndexingFinishedEvent finishedEvent) {
			log.info("index build finished " + this.dateFormat.format(finishedEvent.getSource()));
		}

	}

	@Bean
        .... 
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 12, 2021
@snicoll snicoll added theme: aot type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 13, 2021
@snicoll snicoll added this to the 0.11.1 milestone Dec 13, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 13, 2021

Good catch, it looks like something there isn't taking the user class as it should.

@snicoll snicoll self-assigned this Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

3 participants