Don Rhummy
Don Rhummy

Reputation: 25830

Spring Boot application listener not called

Why is my application listener not called?

@SpringBootApplication
public class Application
{
    @Component
    public static class T implements ApplicationListener<ContextRefreshedEvent>
    {
        @Override
        public void onApplicationEvent(ContextRefreshedEvent event)
        {
            System.out.println( "test" );
        }
    }

    public static void main(String[] args) throws UnknownHostException
    {
        SpringApplication application = new SpringApplication( Application.class );
        ConfigurableApplicationContext run = application.run( args );
    }
}

I put a breakpoint in that method and it's never reached. I see in the logs:

2018-03-30 20:20:57.496 INFO [bootstrap,,,] 84538 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7ce9e05a: startup date [Fri Mar 30 20:20:57 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@78383390

Upvotes: 0

Views: 2273

Answers (1)

houshunwei
houshunwei

Reputation: 41

reason: you need add the following into pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Upvotes: 1

Related Questions