由于某些原因,我的团队在Java配置上使用spring XML配置。实施新的"exclude": [
"node_modules/jointjs/types/geometry.d.ts",
"node_modules/jointjs/types/vectorizer.d.ts",
"node_modules/jointjs/types/joint.d.ts",
"node_modules/jointjs/types/joint.head.d.ts"
]
时,我用Google搜索并找到了如下的Java Config示例:
CorsFilter
但是如何转换为等效的Spring XML配置?我知道我们可以创建一个名为@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);
}
}
的bean并设置一些属性值。但是,如何在XML配置中重写父方法并执行具有副作用的操作? (如在上面添加标题)
答案 0 :(得分:0)
如果要将所有标头配置移到spring xml中,可以在xml中创建一个Map
对象,然后将其设置为属性CorsFilter
并在{{1}中读取}方法。
doFilterInternal