gpt4 book ai didi

java - Spring Boot AuthenticationFilterConfiguration.onStartup 未调用

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

我有以下配置类:

@Configuration
public class AuthenticationFilterConfiguration extends SpringBootServletInitializer {

private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationFilterConfiguration.class);

public AuthenticationFilterConfiguration(){
LOGGER.info("Setting up authentication filter");
}

@Override
public void onStartup(ServletContext context) throws ServletException {
super.onStartup(context);
LOGGER.info("Authentication filter configured");
}

}

这与主应用程序位于同一包中:

@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}

在我的日志中 - 我看到:

2018-04-10 AuthenticationFilterConfiguration : Setting up authentication filter

但是,我从未看到来自 onStartup(...) 的日志消息方法说 Authentication filter configured 。我的另一个@Configuration正在加载类(它们创建了很多 @Bean )

为什么onStartup方法没有被调用?其他一切都正常,我的 RESTful 端点正在工作,等等......

最佳答案

结果我需要实现 ServletContextInitializer 而不是 Spring Boot 类。这工作得很好:

@Configuration
public class AuthenticationFilterConfiguration implements ServletContextInitializer {

private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationFilterConfiguration.class);

public AuthenticationFilterConfiguration(){
LOGGER.info("Setting up authentication filter");
}

@Override
public void onStartup(ServletContext context) throws ServletException {
LOGGER.info("Authentication filter configured");
}

}

关于java - Spring Boot AuthenticationFilterConfiguration.onStartup 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49757130/

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