我在Angular 9和Spring Boot之间建立会话时遇到问题。
在致电localhost:8080/test
时,我总是从服务器上收到相同的SessionId
。
但是,当我通过Angular 9调用相同的端点时,
this.http.get('localhost:8080/test').subscribe()
我得到每个呼叫不同的SessionId。为什么?
WebSecurityConfig.java
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and()
.csrf()
.and()
.cors().disable()
.authorizeRequests()
.antMatchers("/test").permitAll()
.anyRequest().authenticated()
}
TestEndpoint.java
@RestController
@Slf4j
public class TestEndpoint {
@Autowired
HttpSession session;
@GetMapping("/test")
public void test(){
log.info(session.getId());
}
}