相关疑难解决方法(0)

Angular2 / Spring Boot允许在PUT上交叉原点

我的Web应用程序存在一个小问题:一个与spring boot API连接的angular2应用程序。

我无法从angular2应用访问我的请求。我收到此错误:

Failed to load http://localhost:8080/deliveryMan/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

Java代码:

@RestController
@RequestMapping(value = "/deliveryMan")
@CrossOrigin
public class DeliveryManController {

    @Autowired
    DeliveryManService deliveryManService;

    @RequestMapping(value = "/getAllDeliveryMan", method = RequestMethod.GET)
    public Iterable<DeliveryMan> getAllDeliveryMan(){
        return deliveryManService.findAll();
    }

    @RequestMapping(method = RequestMethod.PUT, consumes = "application/json")
    public DeliveryMan addDeliveryMan(@RequestBody DeliveryMan deliveryMan) throws InvalidObjectException {
        deliveryManService.save(deliveryMan);
        return deliveryMan;
    }

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class MyApp{

    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, …
Run Code Online (Sandbox Code Playgroud)

javascript java spring angular

1
推荐指数
1
解决办法
2810
查看次数

标签 统计

angular ×1

java ×1

javascript ×1

spring ×1