Cros Origin + Spring + Angular 4/5

Asked

Viewed 46 times

1

I’m having a problem with my restful service with spring. Even after enabling CORS, I can’t connect with my angular application.

@CrossOrigin
public class UsuarioController {

    @Autowired
    UsuarioService service; 

    @RequestMapping(method = RequestMethod.GET, value = "/lista_todos_usuarios", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Collection<Usuario>> buscaTodosUsuarios() {
        Collection<Usuario> usuarios = service.buscaTodosUsuarios();
        return new ResponseEntity<>(usuarios, HttpStatus.OK);

    }
}

Below is the message in the browser console.

inserir a descrição da imagem aqui

  • Sorry for the delay (I spent a few days offline). In my case I only used the annotation @Crossorigin of spring same. However it is possible to pass parameters to free access to the service, only the origin I want. In my case, I decided to release to any source (study only).

  • Solved issue. Missing @Restcontroller annotation. hehehe

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.