2017-06-15 44 views

回答

1

嘗試自動裝配HttpServletRequest對象插入到LoginEventListener組件,因爲在一個servlet容器中運行的組件。

@Component 
@Slf4j 
public class LoginEventListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> { 

    @Autowired 
    private HttpServletRequest request;  

    @Override 
    public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) { 
     log.info("hahaha: " + event.toString()); 
     log.info("Request Object: " + request); // You now have access to the HTTP request object. 
    } 

} 
0

Tks,只是分享另一種方式來得到它。

HttpServletRequest request = 
       ((ServletRequestAttributes) RequestContextHolder. 
         currentRequestAttributes()). 
         getRequest(); 
相關問題