NutzCN Logo
问答 通过mvc访问接口时,经常报类型转换错误:...$$NUTZAOP cannot be cast to ...
发布于 1711天前 作者 robinhood725 1428 次浏览 复制 上一个帖子 下一个帖子
标签:

我的nutz版本是1.r.63.r2
使用mvc定义了两个controller:DataController、FolderController
我在前端同时发两个请求,一个请求FolderController的service/folder/queryFolders接口;一个请求DataController的service/data/getUserTableMetas接口
有时getUserTableMetas的请求会报以下错误:

java.lang.ClassCastException: com.gistech.ba.controller.DataController$$NUTZAOP cannot be cast to com.gistech.ba.controller.FolderController
	at com.gistech.ba.controller.FolderController$FM$queryFolders$c2c1340a494ba25832f2f6a9154f67a1.invoke(FolderController.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.gistech.ba.filter.AccessControlFilter.process(AccessControlFilter.java:162)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:62)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.gistech.ba.filter.CorsFilter.doFilter(CorsFilter.java:50)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

FolderController定义如下:

@IocBean
@At("/service/folder")
public class FolderController {
	
	@Aop({ "analog" })
	@At("/queryFolders")
	@GET
	@POST
	@Ok("json")
	public Response queryFolders(@Param("tag") String tag, @Param("parentId") String parentId, @Param("folderName") String folderName,
			HttpServletRequest request) {
		Response res = Response.getInstance();
		return res;
	}
}

DataController定义如下:

@IocBean
@At("/service/data")
public class DataController {

	@Aop({ "analog" })
	@At("/getUserTableMetas")
	@GET
	@POST
	@Ok("json")
	public Response getUserTableMetas(@Param("currentPage") int currentPage, @Param("pageSize") int pageSize,
			@Param("keyword") String keyword, @Param("folderId") String folderId, HttpServletRequest request) {
		Response res = Response.getInstance();
		return res;
	}
}

麻烦帮忙看下是什么原因,谢谢!

6 回复

适配器是upload?

应该是ioc相关的问题

去掉aop看看报什么

我把两个接口前的@Aop({ "analog" })都去掉了,报的错误和之前一样的

解决问题了。
因为我使用了nutz的processor和filter定制了一个过滤器:com.gistech.ba.filter.AccessControlFilter:

public class AccessControlFilter extends AbstractProcessor implements ActionFilter {


	@Override
	public View match(ActionContext ac) {

		return null;
	}

	@Override
	public void process(ActionContext ac) throws Throwable {
		try {
			doNext(ac);
		} catch (Exception e) {
			
		}
	}
}

并且在MainModule中从ioc获取他:

@Fail("json")
@IocBy(type = ComboIocProvider.class, args = {
		"*org.nutz.ioc.loader.json.JsonLoader", "/properties/config.js",
		"*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "com.gistech.ba" })
@Modules(scanPackage = true)
@Encoding(input = "UTF-8", output = "UTF-8")
@SetupBy(MainSetup.class)
@Filters(@By(type = AccessControlFilter.class, args = { "ioc:accessControlFilter" }))
public class MainModule {
	
}

http://nutzam.com/core/mvc/action_chain.html
我看到这个关于动作链的网页最后一行说明:从ioc获取处理器应该保持其不为单例,所以我在nutz的配置文件config.js中声明AccessControlFilter时设置了singleton : false,问题得到解决。

虽然我看了源码,但对于解决方案和问题之间的关系还不是很明白,有时间麻烦帮我分析一下,谢谢。

在调用开头说过的两个接口:FolderController的service/folder/queryFolders、DataController的service/data/getUserTableMetas接口 时,都会进入这个过滤器,然后在过滤器内部执行process方法时就报了最开始贴出来的异常信息

添加回复
请先登陆
回到顶部