我有一个SpringMVC
网络应用程序,我在Object property
中设置了HandlerInterceptorAdapter
的值:
public class SpringMVCFilter extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Interceptor.ss = "foo"; // it's a static field
return super.preHandle(request, response, handler);
}
...more code hidden
}
然后,我在MySQL QueryInterceptor
中得到了值:
public class Interceptor implements QueryInterceptor {
public static String ss = null;
@Override
public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) {
System.out.println(ss); // I have set the value for 'ss' before
return null;
}
...more code hidden
}
ss
显然是一个静态变量,我给它分配了一个值,为什么我不能在QueryInterceptor
中获得该值,它们在某个线程中,但是{{1} }始终显示ss
,执行顺序首先分配。
环境:
mysql:mysql-connector-java:8.0.13
春季靴子2.0.2.RELEASE