Search code examples
spring-mvcspring-bootcontrollerhttp-status-code-403request-mapping

403 - Forbidden error for a Request Mapping in Spring MVC


I am writing a simple Spring MVC Controller with a few basic Request Mappings as follows.

@Controller
public class UserController {

    @RequestMapping("/showReg")
    public String showRegistration() {
        return "login/registerUser";        
    }

    @RequestMapping("/showReg1")
    public String showRegistration1() {
        return "login/registerUser";        
    }
}

Accessing localhost:8080/showReg gives the desired result.

But, localhost:8080/showReg1 is giving me 403 - Forbidden.

I am sure I am missing something very simple. What exactly is it? Kindly help me resolve the issue.


Solution

  • By default all the urls are secured in spring security.

    Check your security config file. you might have opened the url from the security something like below.

    For xml configuration :

    <http pattern="/showReg" security="none"/>
    

    OR java configuration :

    @Override
    public void configure(WebSecurity web) throws Exception {
         web.ignoring()
            .antMatchers("/showReg/**");
    }