Angularjs 为什么我得到的职位不允许(405)?

Angularjs 为什么我得到的职位不允许(405)?,angularjs,spring,spring-mvc,Angularjs,Spring,Spring Mvc,我正在使用AngularJs、前端的引导和后端的Java-SpringMVC-SpringSecurityHibernate。 1.所以我创建了一个用户 2.我登录 3.我填写profil表格,当保存时,我有一个405错误 我不明白为什么我在发出post请求时会出现405错误 这是我从AngularJS服务发送的请求: save : function(user) { return $http({ method: 'POST',

我正在使用AngularJs、前端的引导和后端的Java-SpringMVC-SpringSecurityHibernate。 1.所以我创建了一个用户 2.我登录 3.我填写profil表格,当保存时,我有一个405错误

我不明白为什么我在发出post请求时会出现405错误

这是我从AngularJS服务发送的请求:

save : function(user) {
            return $http({
                method: 'POST',
                url: 'http://localhost:8080/app-web/user/profil/'+user.id+'/create',

                data:user
            })
我有
http://localhost:8080/app-web/user/profil/49/创建失败,状态为405
以下是我的Spring安全配置文件片段:

<sec:http realm="Protected API" use-expressions="true" auto-config="false"  create-session="stateless" entry-point-ref="unauthorizedEntryPoint" authentication-manager-ref="authenticationManager">
        <sec:custom-filter ref="authenticationTokenProcessingFilter" position="FORM_LOGIN_FILTER" />
        <sec:intercept-url pattern="/login" access="permitAll" />
        <sec:intercept-url pattern="/user/**" access="permitAll" />
        <sec:intercept-url pattern="/user/profil/**" access="permitAll" />
        <sec:intercept-url pattern="/user/**" access="permitAll" />
    </sec:http>
弹簧日志:

21:40:40.617 [http-bio-8080-exec-4] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Authorization successful
21:40:40.617 [http-bio-8080-exec-4] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - RunAsManager did not change Authentication object
21:40:40.617 [http-bio-8080-exec-4] DEBUG o.s.security.web.FilterChainProxy - /user/profil/49/create reached end of additional filter chain; proceeding with original chain
21:40:40.617 [http-bio-8080-exec-4] INFO  c.d.j.web.filters.SimpleCORSFilter -  Request ====> 127.0.0.1 ===> java.util.Collections$2@25709a84
21:40:40.623 [http-bio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'app' processing POST request for [/app-web/user/profil/49/create]
21:40:40.625 [http-bio-8080-exec-4] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /user/profil/49/create
21:40:40.627 [http-bio-8080-exec-4] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/user/profil/49/create]
21:40:40.627 [http-bio-8080-exec-4] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/user/profil/49/create] are [/**]
21:40:40.627 [http-bio-8080-exec-4] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/user/profil/49/create] are {}
21:40:40.628 [http-bio-8080-exec-4] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/user/profil/49/create] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@663ef60] and 1 interceptor
21:40:40.629 [http-bio-8080-exec-4] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@663ef60]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
21:40:40.630 [http-bio-8080-exec-4] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@663ef60]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
21:40:40.630 [http-bio-8080-exec-4] WARN  o.s.web.servlet.PageNotFound - Request method 'POST' not supported
21:40:40.630 [http-bio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'app': assuming HandlerAdapter completed request handling
21:40:40.630 [http-bio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
21:40:40.630 [http-bio-8080-exec-4] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
21:40:40.631 [http-bio-8080-exec-4] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed

这是一个疏忽错误,该类未设置为控制器。因此,我将UserProfilController更改为

@Controller
public class UserProfileController {

    @RequestMapping(value="/user/profil/{userid}/create", method= RequestMethod.POST)
    @ResponseBody
    public String createProfil(@RequestBody User user){
        // my logic
        return "OK";
    }

}

你有没有检查过关于Spring MVC和405错误的许多其他问题?是的,我检查了其他帖子,但没有人能帮助我。看看你的日志,它提供了线索。如果你想解决这个错误,你能给我一些解释吗?
@Controller
public class UserProfileController {

    @RequestMapping(value="/user/profil/{userid}/create", method= RequestMethod.POST)
    @ResponseBody
    public String createProfil(@RequestBody User user){
        // my logic
        return "OK";
    }

}