title: Spring boot - POST method not allowed
body: <p>I'm dwelling with this problem... I have a Spring Boot application wit a S2S communication. I have a <code>@RestController</code> method which should accept POST request.</p>
  
  <p>This is the controller</p>
  
  <pre><code>@RestController
  public class PaymentRestController {
  
  @PostMapping("/util/paymentResponse")
      public void savePaymentResponse(@RequestParam boolean transaction_status, @RequestParam String usedToken,
              @RequestParam String transaction_message, @RequestParam String authCode,
              @RequestParam String transactionCode, @RequestParam String orderId, HttpServletRequest request) {
  //business logic
  }
  
  }
  </code></pre>
  
  <p>If i hit this link i get a 405 error, method not allowed</p>
  
  <p>At first time i found that the request was blocked by the CSFR Filter which is enabled on the web application, so I have configured my security in this way</p>
  
  <pre><code>@Configuration
  @ComponentScan("it.besmart")
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
  
      @Autowired
      @Qualifier("customUserDetailsService")
      UserDetailsService userDetailsService;
  
      @Autowired
      CustomSuccessHandler customSuccessHandler;
  
      @Autowired
      CustomAuthenticationFailureHandler customAuthenticationFailureHandler;
  
      @Autowired
      DataSource dataSource;
  
      private final static Logger logger = LoggerFactory.getLogger(SecurityConfiguration.class);
  
      @Autowired
      public void configureGlobalService(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
  
      }
  
      @Bean
      public PasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
      @Bean
      public SwitchUserFilter switchUserFilter() {
          SwitchUserFilter filter = new SwitchUserFilter();
          filter.setUserDetailsService(userDetailsService);
          filter.setSuccessHandler(customSuccessHandler);
          filter.setFailureHandler(customAuthenticationFailureHandler);
          return filter;
      }
  
          protected void configure(HttpSecurity http) throws Exception {
              logger.debug("Webapp security configured");
  
  
              http
  
              .authorizeRequests()
                      .antMatchers("/",  "/home", "/contacts", "/faq", "/privacy", "/register", "/registrationConfirm", "/util/**", "/resendRegistrationToken","/park**", "/oauth/authorize", "/error")
                      .permitAll()
                      .antMatchers("/profile**", "/edit**","/payment**", "/plate**","/notification**", "/addPaymentMethod**", "/logout/impersonate**")
                      .access("hasRole('USER') or hasRole('NOPAYMENT')")
                      .antMatchers("/book**", "/manage**")
                      .access("hasRole('USER')")
                      .antMatchers("/admin**", "/login/impersonate**").access("hasRole('ADMIN')")
                      .antMatchers("/updatePassword").hasAuthority("CHANGE_PASSWORD_PRIVILEGE")
  
                      .and().formLogin().loginPage("/?login=login").loginProcessingUrl("/")                   .successHandler(customSuccessHandler).failureHandler(customAuthenticationFailureHandler).usernameParameter("email").passwordParameter("password").and().rememberMe().rememberMeParameter("remember-me").tokenRepository(persistentTokenRepository()).tokenValiditySeconds(86400).and().exceptionHandling().accessDeniedPage("/accessDenied")
  
                      .and().csrf().ignoringAntMatchers( "/util**")
                      .and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                      .logoutSuccessUrl("/?logout=true").permitAll()
  
  
                      .and().addFilterAfter(switchUserFilter(), FilterSecurityInterceptor.class);
  
          }
  </code></pre>
  
  <p>In this way i'm not getting the CSRF token exception, but still getting the 405 error.
  It's not even a problem of POST because if i change to GET the request and the mapping, i still take the 405 error... And if i try to send a POST, i see in the header response that the Allowed method is POST, if i send it in GET i see allowed method POST... weird</p>
  
  <p>I don't know where to see...</p>