---
title: "jfinal 3.5和jfinal_ext的ControllerExt冲突"
author: "radzhang"
date: "2018-10-25T16:58:13Z"
tags: []
categories: ["开源软件"]
slug: "jfinal-3-5-jfinal-ext-controllerext"
draft: false
lastmod: "2018-10-25T16:58:13Z"
id: 2432755
url: "https://radzhang.iteye.com/blog/2432755"
---

jfinal3.1切换到jfinal3.5后，项目启动就失败了，查看了一下，是jfinal在initActionMapping的时候，有重复的actionkey发生。

后来跟踪代码，看到，

protected void buildActionMapping() {

mapping.clear();

Set&lt;String&gt; excludedMethodName = buildExcludedMethodName();

InterceptorManager interMan = InterceptorManager.me();

for (Routes routes : getRoutesList()) {

for (Route route : routes.getRouteItemList()) {

Class&lt;? extends Controller&gt; controllerClass = route.getControllerClass();

Interceptor\[] controllerInters = interMan.createControllerInterceptor(controllerClass);

在buildExcludeMethodName里，会把Controller基类的方法都去除。

而我的项目的controller是扩展了jfinal\_ext里的ControllerExt基类。在ControllerExt基类里，定义了getFileSaveToDatePath等不同参数类型的方法，

protected void buildActionMapping() {

mapping.clear();

Set&lt;String&gt; excludedMethodName = buildExcludedMethodName();

InterceptorManager interMan = InterceptorManager.me();

for (Routes routes : getRoutesList()) {

for (Route route : routes.getRouteItemList()) {

Class&lt;? extends Controller&gt; 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失败。