3.8版本 升级到4.1时异常
getBrand方法前有调用拦截器@Before(PolicesInterceptor.class)
错误: 未报告的异常错误java.lang.Exception; 必须对其进行捕获或声明以便抛出
问题描述:
/** *函数名称:getBrand *函数参数: *返 回 值:List<BasBrand> *函数功能:根椐用户编码所拥有的权限获取品牌权限列表信息 ***/ @Before(PolicesInterceptor.class) public List<BasBrand> getBrand() throws Exception{ String key = getUser().get("cloudwarehouse") + this.getUserCode(); List<BasBrand> brandlist = CacheKit.get(brandCacheName, key); if(brandlist == null){ String sql = "select b.brand_code,b.brand_name from bas_brand b order by b.brand_code"; brandlist = BasBrand.dao.find(sql); if(brandlist!=null && brandlist.size()>0){ CacheKit.put(brandCacheName, key, brandlist); } } return brandlist; } 启动过程报错如下: Starting JFinal 4.1 -> http://0.0.0.0:8080 Info: jfinal-undertow 1.6, undertow 2.0.19.Final, jvm 1.8.0_181 2019-06-01 11:59:37 [ERROR]-[Thread: main]-[com.jfinal.proxy.ProxyCompiler.lambda$compile$0()]: /SelectService$$EnhancerByJFinal.java:9: 错误: 未报告的异常错误java.lang.Exception; 必须对其进行捕获或声明以便抛出 return SelectService$$EnhancerByJFinal.super.getBrand( ^ java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.wms.common.service.SelectService$$EnhancerByJFinal at com.jfinal.aop.InterceptorManager.createInterceptor(InterceptorManager.java:172) at com.jfinal.aop.InterceptorManager.createInterceptor(InterceptorManager.java:150) at com.jfinal.aop.InterceptorManager.doBuild(InterceptorManager.java:82) at com.jfinal.aop.InterceptorManager.buildControllerActionInterceptor(InterceptorManager.java:74) at com.jfinal.core.ActionMapping.buildActionMapping(ActionMapping.java:81) at com.jfinal.core.JFinal.initActionMapping(JFinal.java:103) at com.jfinal.core.JFinal.init(JFinal.java:64) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:63) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:589) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:554) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:596) at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:284) at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:262) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:159) at com.wms.common.config.WmsConfig.main(WmsConfig.java:288) Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.wms.common.service.SelectService$$EnhancerByJFinal at com.jfinal.proxy.ProxyClassLoader.loadProxyClass(ProxyClassLoader.java:51) at com.jfinal.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:70) at com.jfinal.proxy.ProxyFactory.get(ProxyFactory.java:41) at com.jfinal.proxy.Proxy.get(Proxy.java:32) at com.jfinal.aop.AopFactory.createObject(AopFactory.java:173) at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:87) at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65) at com.jfinal.aop.AopFactory.doInject(AopFactory.java:157) at com.jfinal.aop.AopFactory.inject(AopFactory.java:125) at com.jfinal.aop.Aop.inject(Aop.java:105) at com.jfinal.aop.InterceptorManager.createInterceptor(InterceptorManager.java:165) ... 18 more Caused by: java.lang.ClassNotFoundException: com.wms.common.service.SelectService$$EnhancerByJFinal at java.lang.ClassLoader.findClass(ClassLoader.java:530) at com.jfinal.proxy.ProxyClassLoader.findClass(ProxyClassLoader.java:64) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.jfinal.proxy.ProxyClassLoader.loadProxyClass(ProxyClassLoader.java:49) ... 28 more
解决方法: 去掉getBrand的throws Exception ,可以正常启动
/** *函数名称:getBrand *函数参数: *返 回 值:List<BasBrand> *函数功能:根椐用户编码所拥有的权限获取品牌权限列表信息 ***/ @Before(PolicesInterceptor.class) public List<BasBrand> getBrand(){ String key = getUser().get("cloudwarehouse") + this.getUserCode(); List<BasBrand> brandlist = CacheKit.get(brandCacheName, key); if(brandlist == null){ String sql = "select b.brand_code,b.brand_name from bas_brand b order by b.brand_code"; brandlist = BasBrand.dao.find(sql); if(brandlist!=null && brandlist.size()>0){ CacheKit.put(brandCacheName, key, brandlist); } } return brandlist; } Starting JFinal 4.1 -> http://0.0.0.0:8080 Info: jfinal-undertow 1.6, undertow 2.0.19.Final, jvm 1.8.0_181 Starting Complete in 2.5 seconds. Welcome To The JFinal World (^_^)
为什么3.8正常,升4.1后就不能用throws Exception,看是那里使用不对造成的 需要怎么解决
项目:JFinal
这个是忘了在子类中生成 throws 代码块了,为了彻底解决升级可能的问题, jfinal 会在 com.jfinal.ext 包下面提供一个扩展,当然,你碰到的这个问题会在 com.jfinal.proxy 里头解决。 扩展用于防患于未然