jfinal 3.5和jfinal_ext的ControllerExt冲突
jfinal3.1切换到jfinal3.5后,项目启动就失败了,查看了一下,是jfinal在initActionMapping的时候,有重复的actionkey发生。
后来跟踪代码,看到,
protected void buildActionMapping() {
mapping.clear();
Set<String> excludedMethodName = buildExcludedMethodName();
InterceptorManager interMan = InterceptorManager.me();
for (Routes routes : getRoutesList()) {
for (Route route : routes.getRouteItemList()) {
Class<? extends Controller> controllerClass = route.getControllerClass();
Interceptor[] controllerInters = interMan.createControllerInterceptor(controllerClass);
在buildExcludeMethodName里,会把Controller基类的方法都去除。
而我的项目的controller是扩展了jfinal_ext里的ControllerExt基类。在ControllerExt基类里,定义了getFileSaveToDatePath等不同参数类型的方法,
protected void buildActionMapping() {
mapping.clear();
Set<String> excludedMethodName = buildExcludedMethodName();
InterceptorManager interMan = InterceptorManager.me();
for (Routes routes : getRoutesList()) {
for (Route route : routes.getRouteItemList()) {
Class<? extends Controller> controllerClass = route.getControllerClass();
Interceptor[] controllerInters = interMan.createControllerInterceptor(controllerClass);
boolean sonOfController = (controllerClass.getSuperclass() == Controller.class);
Method[] methods = (sonOfController ? controllerClass.getDeclaredMethods() : controllerClass.getMethods());
for (Method method : methods) {
String methodName = method.getName();
if (excludedMethodName.contains(methodName) /* || method.getParameterTypes().length != 0 */)
continue ;
if (sonOfController && !Modifier.isPublic(method.getModifiers()))
continue ;
if (method.getAnnotation(NotAction.class) != null)
但是在3.5因为action也允许有参数注入了,所以这个地方把getParameterTypes()这个条件注释掉了,导致buildActionMapping失败。