Spring Boot and Rest Services (405 Method not Supported) -
i created simple spring boot app , crated rest service , when tried access i'm getting error
405 : method not supported
not sure what's issue. checked method annotations , specified method=requestmethod.post , submitting form post method.
here code.
@springbootapplication public class ssfirstapplication { public static void main(string[] args) { springapplication.run(ssfirstapplication.class, args); } } and rest service
@restcontroller @requestmapping("/api") public class userxauthtokencontroller { @inject private userdetailsservice userdetailsservice; @requestmapping(value = "/authenticate", method = requestmethod.post) public userdetails authorize(@requestparam string username, @requestparam string password) { userdetails details = this.userdetailsservice.loaduserbyusername(username); return details ; } } and index.html page pretty basic.
<html> <body> <h3>welcome</h3> <form action="/api/authenticate" method="post"> <div> <div> <label>user name : </label> <input type="text" name="username"/> </div> <div> <label>password : </label> <input type="password" name="password"/> </div> <div> <input type="submit" value="submit"/> </div> </div> </form> </body> </html> and here console log
2015-05-14 13:38:37.525 info 8124 --- [nio-9090-exec-1] o.a.c.c.c.[tomcat].[localhost].[/] : initializing spring frameworkservlet 'dispatcherservlet' 2015-05-14 13:38:37.525 info 8124 --- [nio-9090-exec-1] o.s.web.servlet.dispatcherservlet : frameworkservlet 'dispatcherservlet': initialization started 2015-05-14 13:38:37.565 info 8124 --- [nio-9090-exec-1] o.s.web.servlet.dispatcherservlet : frameworkservlet 'dispatcherservlet': initialization completed in 40 ms 2015-05-14 13:38:37.590 warn 8124 --- [nio-9090-exec-1] o.s.web.servlet.pagenotfound : request method 'post' not supported not sure doing wrong. appreciate response.
i able resolve issue. added following annotations main class @enableautoconfiguration @componentscan.
now main class looks this.
@springbootapplication @enableautoconfiguration @componentscan({"com"}) public class ssfirstapplication { public static void main(string[] args) { springapplication.run(ssfirstapplication.class, args); } } i thought these added automatically @springbootapplication apparently not. thanks
Comments
Post a Comment