NutzCN Logo
问答 org.nutz.lang.InvokingException: Fail to invoke怎么处理?
发布于 2679天前 作者 qq_7fafbecc 1765 次浏览 复制 上一个帖子 下一个帖子
标签:

org.nutz.lang.InvokingException: Fail to invoke [com.shlx.blood.service.dict.DictService].queryProjectById() by args:
{projectId=}
For the reason: com/shlx/blood/entity/dict/Project

代码如下:

public List<Project> getProjectById(String projectId) {

    Cnd cnd = (Cnd)Cnd.where("1", "=", "1");
    projectId = projectId.trim();
    if(projectId!=null && !"".equals(projectId)){
       cnd = cnd.and("projectId", "=", projectId);
    }
    cnd.asc("projectId");
    //返回结果的LIST
    List<Project> rval = new ArrayList<Project>();
    List<Project> returnList = new ArrayList<Project>();
    //循环取值,并赋进去childNum
    rval = dao.query(Project.class, cnd);
    return rval;
}

执行到dao.query(Project.class, cnd)这句异常就出来了,难道是Project实体类有问题吗?

16 回复

贴完整的 log

来自美丽的 NutzCN

2017-07-16 13:27:00,010 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
2017-07-16 13:27:00,010 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dictServiceBo'<class com.shlx.blood.service.bo.DictServiceBo>
2017-07-16 13:27:00,010 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=dictServiceBo
2017-07-16 13:27:00,011 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(dictServiceBo) in AnnotationIocLoader(packages=[com.shlx.blood])
2017-07-16 13:27:00,011 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'dictServiceBo'<class com.shlx.blood.service.bo.DictServiceBo>
2017-07-16 13:27:00,011 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class com.shlx.blood.service.bo.DictServiceBo without AOP
2017-07-16 13:27:00,011 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'dictServiceBo' to [app]
2017-07-16 13:27:00,012 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dao'<interface org.nutz.dao.Dao>
{projectId=}
org.nutz.lang.InvokingException: Fail to invoke [com.shlx.blood.service.dict.DictService].queryProjectById() by args:
{projectId=}
For the reason: com/shlx/blood/entity/dict/Project

控制台就只有这些日志了。。。。

这是哪里打印的日志, 把调用queryProjectById方法的代码贴出来

@At("/queryProjectById")
public Object queryProjectById(@Param("projectId")String projectId) {
Object result = null;
//封装参数
NutMap re = new NutMap();
re.setv("projectId", projectId);
result = comServices.ExcuteServices("B06.01.02", re);
return result;
//return Json.toJson(result);
}

ExcuteServices里面是反射调用方法

/**
* 统一的方法进入
* @param _function_no
* @param _params
* @return JSON数据
*/
public Object ExcuteServices(String _function_no, NutMap _params) {
log.info("function_no : " + _function_no + " params:" + _params.toString());
//获取这个功能号的配置
List sysfunctions = dao.query(SysFunction.class, Cnd.where("functionid", "=", _function_no));
if(sysfunctions == null || sysfunctions.isEmpty()) {
return GetSystemExcepitonResponse(String.format("找不到功能编号为%s的方法!", _function_no));
}
SysFunction sysfunction = sysfunctions.get(0);
if(Strings.isEmpty(sysfunction.getFunctionId()) || Strings.isEmpty(sysfunction.getServiceClass()) || Strings.isEmpty(sysfunction.getServiceMethod())) {
return GetSystemExcepitonResponse(String.format("功能编号%s的配置错误!", _function_no));
}
//获得命名空间
//String _nameSpace = Strings.endsWithChar(sysfunction.getServiceClass(), '.') ? sysfunction.getServiceClass() : sysfunction.getServiceClass() + ".";
//获得服务名称
String services_name = sysfunction.getServiceClass();
//通过反射判断这个类是否存在
//反射之中的所有泛型都定义为?,返回值都是Object
Class<?> services_class;
try {
services_class = Class.forName(services_name);
}
catch (ClassNotFoundException e) {
return GetSystemExcepitonResponse(String.format("%s服务类没有找到!", services_name));
}
//判断这个类是否在IOC容器中存在
Object obj;
try {
obj = Mvcs.getIoc().get(services_class);
} catch (IocException e) {
return GetSystemExcepitonResponse(String.format("%s服务类在IOC容器中没有找到,请注意类是否为IOC管理!", services_name));
}
//通过反射调用方法
Mirror mirror = Mirror.me(obj.getClass());
//获得所有方法--判断是否存在
boolean hasMethod = false;
Method[] methods = mirror.getMethods();
for (Method method : methods) {
String methodName = method.getName();
if(methodName.toUpperCase().equals(sysfunction.getServiceMethod().toUpperCase())) {
hasMethod = true;
break;
}
}
if(!hasMethod) {
return GetSystemExcepitonResponse(String.format("%s服务类的{1}方法没有找到!", services_name, sysfunction.getServiceMethod()));
}
//判断权限除了登录方法 -- 先取SESSION,如SESSION中没有,就为WebServices传入
if(!_function_no.equals(Globals.LOGIN_FUNCTION_ID) && (sysfunction.getIsMustBind() == null || !"1".equals(sysfunction.getIsMustBind()))) {
SysUser user = (SysUser)Mvcs.getHttpSession().getAttribute(Globals.SESSION_USER_CODE);
if(user != null) {
//获得角色编号
List userRoleList = new ArrayList();
userRoleList = dao.query(UserRole.class, Cnd.where("userId","=",user.getUserId()));
if(userRoleList.size() == 0){
return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
}
// String roleId = user.getRoleId();
// if(roleId == null || roleId.equals("")) {
// return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
// }
//判断是不是管理员
boolean isAdmin = false;
for(int i=0; i<userRoleList.size(); i++){
UserRole ur = userRoleList.get(i);
Role role = dao.fetch(Role.class, Cnd.where("rolecode","=",ur.getRoleCode()));
String roleType = role.getRoleType();
if("0".equals(roleType)){
//有系统管理员的角色
isAdmin = true;
break;
}
}

         if(!isAdmin){
          //没有管理员权限
          //查询数据库是否有权限
          boolean isExist = false;
          for(int i=0; i<userRoleList.size(); i++){
              UserRole ur = userRoleList.get(i);
              RoleFunction roleFunction = dao.fetch(RoleFunction.class, Cnd.where("rolecode","=",ur.getRoleCode()).and("functionid","=",_function_no));
              if(roleFunction != null){
                 isExist = true;
                 break;
              }
          }
          if(!isExist){
              return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
          }
         }

// Role role = dao.fetch(Role.class, roleId);
// if(!role.getIsAdmin().equals("1")) {
// //查询数据库是否有权限
// RoleFunction roleFunction = dao.fetchx(RoleFunction.class, roleId, _function_no);
// if(roleFunction == null) {
// return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
// }
// }
} else {
//判断是否为Webservices进入
if(_params.containsKey(Globals.WEBSERVICES_ROLE)) {
RoleFunction roleFunction = dao.fetchx(RoleFunction.class, _params.get(Globals.WEBSERVICES_ROLE), _function_no);
if(roleFunction == null) {
return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
}
} else {
return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
}
}
}
//TODO 检查参数配置
try {
if(sysfunction.getNoCodeResponse() != null && "1".equals(sysfunction.getNoCodeResponse())){
//返回没有code的json形式
return mirror.invoke(obj, sysfunction.getServiceMethod(), _params);
}else{
return this.GetOkResponse(mirror.invoke(obj, sysfunction.getServiceMethod(), _params));
}
}
catch (Exception ex) {
if (ex.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException)ex.getCause();
return this.GetBusinessExceptionResponse(businessException.getMessage());
} else if(ex.getCause() instanceof SystemException) {
SystemException systemException = (SystemException)ex.getCause();
return this.GetSystemExcepitonResponse(systemException.getMessage());
} else {
return this.GetSystemExcepitonResponse(ex.getMessage());
}
}
}

按"插入代码或日志片段"的按钮重新贴!!

public Object ExcuteServices(String _function_no, NutMap _params) {
		log.info("function_no : " + _function_no + " params:" + _params.toString());
		//获取这个功能号的配置
		List<SysFunction> sysfunctions = dao.query(SysFunction.class, Cnd.where("functionid", "=", _function_no));
		if(sysfunctions == null || sysfunctions.isEmpty()) {
			return GetSystemExcepitonResponse(String.format("找不到功能编号为%s的方法!", _function_no));
		}
		SysFunction sysfunction = sysfunctions.get(0);
		if(Strings.isEmpty(sysfunction.getFunctionId()) || Strings.isEmpty(sysfunction.getServiceClass()) || Strings.isEmpty(sysfunction.getServiceMethod())) {
			return GetSystemExcepitonResponse(String.format("功能编号%s的配置错误!", _function_no));
		}
		//获得命名空间
		//String _nameSpace = Strings.endsWithChar(sysfunction.getServiceClass(), '.') ? sysfunction.getServiceClass() : sysfunction.getServiceClass() + ".";
		//获得服务名称
		String services_name = sysfunction.getServiceClass();
		//通过反射判断这个类是否存在
		//反射之中的所有泛型都定义为?,返回值都是Object
		Class<?> services_class;
		try {
			services_class = Class.forName(services_name);
		}
		catch (ClassNotFoundException e) {
			return GetSystemExcepitonResponse(String.format("%s服务类没有找到!", services_name));
		}
		//判断这个类是否在IOC容器中存在
		Object obj;
		try {
			obj = Mvcs.getIoc().get(services_class);
		} catch (IocException e) {
			return GetSystemExcepitonResponse(String.format("%s服务类在IOC容器中没有找到,请注意类是否为IOC管理!", services_name));
		}
		//通过反射调用方法
		Mirror mirror = Mirror.me(obj.getClass());
		//获得所有方法--判断是否存在
		boolean hasMethod = false;
		Method[] methods = mirror.getMethods();
		for (Method method : methods) {
			String methodName = method.getName();
			if(methodName.toUpperCase().equals(sysfunction.getServiceMethod().toUpperCase())) {
				hasMethod = true;
				break;
			}
		}
		if(!hasMethod) {
			return GetSystemExcepitonResponse(String.format("%s服务类的{1}方法没有找到!", services_name, sysfunction.getServiceMethod()));
		}
		//判断权限除了登录方法 -- 先取SESSION,如SESSION中没有,就为WebServices传入
		if(!_function_no.equals(Globals.LOGIN_FUNCTION_ID) && (sysfunction.getIsMustBind() == null || !"1".equals(sysfunction.getIsMustBind()))) {
			SysUser user = (SysUser)Mvcs.getHttpSession().getAttribute(Globals.SESSION_USER_CODE);
			if(user != null) {
				//获得角色编号
				List<UserRole> userRoleList = new ArrayList<UserRole>(); 
				userRoleList = dao.query(UserRole.class, Cnd.where("userId","=",user.getUserId()));
				if(userRoleList.size() == 0){
					return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
				}
//				String roleId = user.getRoleId();
//				if(roleId == null || roleId.equals("")) {
//					return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
//				}
				//判断是不是管理员
				boolean isAdmin = false;
				for(int i=0; i<userRoleList.size(); i++){
					UserRole ur = userRoleList.get(i);
					Role role = dao.fetch(Role.class, Cnd.where("rolecode","=",ur.getRoleCode()));
					String roleType = role.getRoleType();
					if("0".equals(roleType)){
						//有系统管理员的角色
						isAdmin = true;
						break;
					}
				}

				if(!isAdmin){
					//没有管理员权限
					//查询数据库是否有权限
					boolean isExist = false;
					for(int i=0; i<userRoleList.size(); i++){
						UserRole ur = userRoleList.get(i);
						RoleFunction roleFunction = dao.fetch(RoleFunction.class, Cnd.where("rolecode","=",ur.getRoleCode()).and("functionid","=",_function_no));
						if(roleFunction != null){
							isExist = true;
							break;
						}
					}
					if(!isExist){
						return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
					}
				}
//				Role role = dao.fetch(Role.class, roleId);
//				if(!role.getIsAdmin().equals("1")) {
//					//查询数据库是否有权限
//					RoleFunction roleFunction = dao.fetchx(RoleFunction.class, roleId, _function_no);
//					if(roleFunction == null) {
//						return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
//					}	
//				}
			} else {
				//判断是否为Webservices进入
				if(_params.containsKey(Globals.WEBSERVICES_ROLE)) {
					RoleFunction roleFunction = dao.fetchx(RoleFunction.class, _params.get(Globals.WEBSERVICES_ROLE), _function_no);
					if(roleFunction == null) {
						return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
					}
				} else {
					return GetResponse(Globals.Code.BUSINESS_EXCEPTION_CODE, "当前用户没有使用此功能的权限!");
				}
			}
		}
		//TODO 检查参数配置
		try {
			if(sysfunction.getNoCodeResponse() != null && "1".equals(sysfunction.getNoCodeResponse())){
				//返回没有code的json形式
				return mirror.invoke(obj, sysfunction.getServiceMethod(), _params);
			}else{
				return this.GetOkResponse(mirror.invoke(obj, sysfunction.getServiceMethod(), _params));
			}
		}
		catch (Exception ex) {
			if (ex.getCause() instanceof BusinessException) {
				BusinessException businessException = (BusinessException)ex.getCause();
				return this.GetBusinessExceptionResponse(businessException.getMessage());
			} else if(ex.getCause() instanceof SystemException) {
				SystemException systemException = (SystemException)ex.getCause();
				return this.GetSystemExcepitonResponse(systemException.getMessage());
			} else {
				return this.GetSystemExcepitonResponse(ex.getMessage());
			}
		}
	}

改成这样,打印详细的报错信息

catch (Exception ex) {
    log.debug(ex.getMessage(), e);

跟断点时,在执行return mirror.invoke(obj, sysfunction.getServiceMethod(), _params); 这句时被catch (Exception ex)

2017-07-16 13:40:28,431 com.shlx.blood.service.ComServices.ExcuteServices(ComServices.java:198) DEBUG - Fail to invoke [com.shlx.blood.service.dict.DictService].queryProjectById() by args:
 {projectId=}
For the reason: com/shlx/blood/entity/dict/Project
org.nutz.lang.InvokingException: Fail to invoke [com.shlx.blood.service.dict.DictService].queryProjectById() by args:
 {projectId=}
For the reason: com/shlx/blood/entity/dict/Project
	at org.nutz.lang.Invoking.invoke(Invoking.java:195)
	at org.nutz.lang.Mirror.invoke(Mirror.java:1100)
	at com.shlx.blood.service.ComServices.ExcuteServices(ComServices.java:192)
	at com.shlx.blood.action.dict.DictAction.queryProjectById(DictAction.java:84)
	at com.shlx.blood.action.dict.DictAction$$FASTCLASS._invoke(DictAction.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	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:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/shlx/blood/entity/dict/Project
	at com.shlx.blood.service.bo.DictServiceBo.getProjectById(DictServiceBo.java:112)
	at com.shlx.blood.service.dict.DictService.queryProjectById(DictService.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.lang.Invoking$DefaultInvoker.invoke(Invoking.java:47)
	at org.nutz.lang.Invoking.invoke(Invoking.java:192)
	... 40 more
Caused by: java.lang.ClassNotFoundException: com.shlx.blood.entity.dict.Project
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	... 48 more

我有这个类啊

@wendal 刚把项目从tomcat中移除后,重新编译,重新add进去,再重启就不报错了?
擦,难道是没有把class成功编译进去?

log.debug之后,Class.forName这类名看看报啥

哦, 那就ok啦...

OK了,问题解决了,是Project的编译问题,再次谢谢 @wendal

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