我正在使用教程来描述如何使用Spring Boot,Spring Security和AngularJS编写简单的单页面应用程序:https://spring.io/guides/tutorials/spring-security-and-angular-js/
我无法注销当前登录的用户 - 当我执行POST请求到"/ logout"时,我得到"404 not found" - 来自Google Chrome调试器的屏幕:
为什么要GET?我进行了POST.为什么"/ login?logout",而不是"/ logout"?以下是用户单击注销按钮时调用的代码:
$scope.logout = function() {
$http.post('logout', {}).success(function() {
$rootScope.authenticated = false;
$location.path("/");
}).error(function(data) {
console.log("Logout failed")
$rootScope.authenticated = false;
});
}
Run Code Online (Sandbox Code Playgroud)
春天代码:
@SpringBootApplication
@RestController
public class UiApplication {
@RequestMapping("/user")
public Principal user(Principal user) {
return user;
}
@RequestMapping("/resource")
public Map<String, Object> home() {
Map<String, Object> model = new HashMap<String, Object>();
model.put("id", UUID.randomUUID().toString());
model.put("content", "Hello World");
return model;
}
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud)