如何在Spring XML配置中覆盖父方法?

由于某些原因,我的团队在Java配置上使用spring XML配置。当我实现new时CorsFilter,我用谷歌搜索并找到了示例Java Config,如下所示:


@Component

public class CorsFilter extends OncePerRequestFilter {


   @Override

   protected void doFilterInternal(final HttpServletRequest request,

                                   final HttpServletResponse response,

                                   final FilterChain filterChain) throws ServletException, IOException {

       response.addHeader("Access-Control-Allow-Origin", "*");

       response

               .addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, HEAD, OPTIONS");

       response.addHeader("Access-Control-Allow-Headers",

               "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");

       response.addHeader("Access-Control-Expose-Headers",

               "Access-Control-Allow-Origin, Access-Control-Allow-Credentials");

       response.addHeader("Access-Control-Allow-Credentials", "true");

       response.addIntHeader("Access-Control-Max-Age", 10);

       filterChain.doFilter(request, response);

   }

}

但是如何转换为等效的Spring XML配置呢?我知道我们可以创建一个名为的beancorsFilter并设置一些属性值。但是,如何在XML配置中覆盖父方法并执行具有副作用的操作呢?(如在上面添加标题)


萧十郎
浏览 172回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java