【问题标题】:How to configure <context:component-scan /> in Spring dispatch servlet?如何在 Spring dispatch servlet 中配置 <context:component-scan />?
【发布时间】:2011-12-13 22:14:34
【问题描述】:

我想在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.*中的控制器类方法?

【问题讨论】:

标签: spring spring-mvc oauth-2.0


【解决方案1】:

因为 dispatcher-servlet bean 通常应该是 @Controllers,所以你不应该排除它们。我们在 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>

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 2017-02-04
    相关资源
    最近更新 更多