Basic Spring Boot with Angular

I am trying to get a message printed to my web console when I click a button in my Angular UI.

So far I have done:

My Angular Side:


<button id="b1" mat-raised-button color="primary" type="button"(click)=displayString()>Submit</button>

My .ts file:

  displayString(){'http://localhost:8080/jpmorgan/editquestionSet',{},{ responseType: "text" })
    .subscribe(response => console.log(response) );

My Springboot side:

      public class WebConfig extends WebMvcConfigurerAdapter {
          public void addCorsMappings(CorsRegistry registry) {
                 .allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
    protected void configure(HttpSecurity http) throws Exception {
            .antMatchers(HttpMethod.OPTIONS, "/**")
    CorsConfigurationSource corsConfigurationSource() {
        UrlBasedCorsConfigurationSource source = new 
        source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
        return source;


@CrossOrigin(origins = "*")
public class ApplicationController {
    private CompilationService compilationService;
    public String editquestions() {
        return "Questions Added Successfully";


Error That I am getting in Web console:

zone.js:3243 POST http://localhost:8080/jpmorgan/editquestionSet 401 core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: “OK”, url: “http://localhost:8080/jpmorgan/editquestionSet”, ok: false, …}

Instead of error, I want a response to coming from the spring app:

** Questions Added Successfully **


The following means you are requiring authentication.


Try :


Source: stackoverflow