http://blog.csdn.net/dalangzhonghangxing/article/details/52446821
If you're still having trouble with cross-domain issues, check out the blogger's resolution angular+spring boot cross-domain issue that article.
Bloggers in the project development process, encountered due to cross-domain caused by the loss of the session, very disgusting, but after the online access to a variety of information, found that the solution is very simple.
In each of our data requests, the browser sends a jsession to the background, which automatically finds the session object with ID jsession based on this value. However, when cross-domain, the value of the jsession will change each time, the background will assume that a new session opened, and then to create a new object, and the original session object can not be found.
The solution to this problem is simply to set Withcredentials to true in the request, then the value of the cookie in the header of each request, and the Jsession value is recorded in the cookie, so the session is not lost.
In Angularjs, the global setting can be used to make withcredentials true
[JavaScript]View PlainCopy
- var utils = angular.module (' utils ', []);
- Utils.config ([' $httpProvider ', Config]);
- function Config ($httpProvider) {
- $httpProvider. defaults.withcredentials = true;
- }
Then let the "Utils" be injected into all the apps, and the withcredentials in all the request headers will be set to true so that the session will not be lost.
Of course, you can also set the withcredentials of the current request in the following ways.
[JavaScript]View PlainCopy
- $http. xhr.withcredentials
Spring Boot+angularjs because of cross-domain causes session loss