gpt4 book ai didi

java - Spring Boot 应用程序监听器未调用

转载 作者:行者123 更新时间:2023-12-02 11:26:33 25 4
gpt4 key购买 nike

为什么我的应用程序监听器没有被调用?

@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 );
}
}

我在该方法中放置了一个断点,但它从未到达。我在日志中看到:

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

最佳答案

原因:您需要将以下内容添加到 pom.xml

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

关于java - Spring Boot 应用程序监听器未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49583043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com