【问题标题】:Spring's ApplicationListener<AuthenticationSuccessEvent> breaks the @CrossOriginSpring 的 ApplicationListener<AuthenticationSuccessEvent> 打破了@CrossOrigin
【发布时间】:2021-01-05 08:43:28
【问题描述】:

所以我有这个服务器 Spring 应用程序,在控制器上带有 @CrossOrigin 注释(用于我的 React 客户端)。问题是当我实现这个时:

@Component
public class LoginListener implements ApplicationListener<AuthenticationSuccessEvent> {
    @Autowired
    RealtimeAlertsThreadFactory alertsFactory;

  @Override
  public void onApplicationEvent(AuthenticationSuccessEvent event) {
    UserDetails ud = (UserDetails) event.getAuthentication().getPrincipal();
    
    alertsFactory.createAlerts(ud.getUsername());
  }
}

CORS 开始阻止每个请求。有谁知道这是为什么?

【问题讨论】:

    标签: spring spring-security cors


    【解决方案1】:

    哈哈,只需要给监听器本身添加一个@CrossOrigin :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 2015-09-27
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多