以下是我要做的事情:
8765
上运行。我正在使用此8765
registry.addInterceptor(tokenValidateInterceptor()).addPathPatterns("/**");
对我来说,showstopper是API-GATEWAY的拦截器。我在这里观察到一个奇怪的场景,我想提一下
如果Node.js服务停止拦截器工作正常。但是如果Node.js服务正在运行它甚至没有执行拦截器,但调用是通过API-GATEWAY和我我从Node.js服务获得了必要的响应。
这是我的代码段:
@EnableEurekaClient
@SpringBootApplication
@EnableZuulProxy
@Configuration
public class Application extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Autowired
private TokenValidateInterceptor tokenValidateInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(tokenValidateInterceptor).addPathPatterns("/**");
}
拦截
@Component
public class TokenValidateInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
LOG.info("#### Starting TokenValidateInterceptor.preHandle ####");
String apiKey = null;
try {
apiKey = request.getHeader("apikey");
LOG.info("The request come with apikey ======" + apiKey);
LOG.info("Actual apikey ======" + azureApikey);
}
建议更改或告诉我如果我实施了错误。
答案 0 :(得分:0)
尝试以下配置。应该可以。
@Configuration
public class MyConfiguration extends WebMvcConfigurerAdapter{
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(new MyCustomInterceptor()).addPathPatterns("/**");
}
}