首先在对应的Controller包种引入
import org.springframework.web.bind.annotation.CrossOrigin;
在对应的方法上加上注解
//访问路径
@RequestMapping("/hello")
//支持跨域
@CrossOrigin("http://localhost:8002")
//以JSON格式返回数据
@ResponseBody
public Map<String, Object> showHelloWorld() {
Map<String, Object> map = new HashMap<>();
map.put("msg", "hello");
return map;
}