如何在Spring dispatch servlet中配置<context:component-scan>?</context:component-scan>

时间:2011-10-24 07:43:10

标签: spring spring-mvc oauth-2.0

我想在oauth2类中调用控制器方法 org.springframework.security.oauth2.provider.endpoint

@RequestMapping(value = "/oauth/authorize", method = RequestMethod.POST)
public void approveOrDeny(@RequestParam("user_oauth_approval")
                          boolean approved,
                          HttpServletRequest request,
                          HttpServletResponse response) throws IOException,
                                                               ServletException {
....
}

来自我的申请。要调用上面的类,我尝试使用它。结果是“无法访问”。

<context:component-scan base-package="org.stjude.ri.bwfp">
    <context:include-filter type="regex" expression="org.springframework.security.oauth2.*"/>
    <context:exclude-filter expression=".*_Roo_.*"
        type="regex" />
    <context:exclude-filter expression="org.springframework.stereotype.Controller"
        type="annotation" />
</context:component-scan>

如何调用org.springframework.security.oauth2.provider.*中的控制器类方法?

1 个答案:

答案 0 :(得分:3)

由于dispatcher-servlet bean通常只应为@Controller,因此不应排除它们。我们在dispatcher-servlet.xml使用OAuth时使用了这个,它运行正常:

<context:component-scan base-package="foo.bar.controllers" use-default-filters="false">
    <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>