如何在servlet过滤器中获得Spring Bean?
2022-08-31 22:39:40
我已经定义了一个Java类,我有Spring注释。javax.servlet.Filter
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
@Configuration
public class SocialConfig {
// ...
@Bean
public UsersConnectionRepository usersConnectionRepository() {
// ...
}
}
我想在我的中得到豆子,所以我尝试了以下方法:UsersConnectionRepository
Filter
public void init(FilterConfig filterConfig) throws ServletException {
UsersConnectionRepository bean = (UsersConnectionRepository) filterConfig.getServletContext().getAttribute("#{connectionFactoryLocator}");
}
但它总是返回 。我怎样才能得到一个春豆?null
Filter