abstract class or interface can not be

问题描述

从Mybatis的Aop容器容器中获取mapper对象,获取成功

将mybatis的的mapper对象放入jfinal 的aop容器中,放入成功

但是从jfinal的Aop容器中获取对象是时出现错误

因为mybatis 的mapper对象是一个接口

java.lang.IllegalArgumentException: abstract class or interface can not be proxied

有没有其他解决办法可以解决该问题?

出现异常的代码

  /**
   * 将Mapper添加到Aop容器中
   * @param sqlSession
   */
  private void addMapperToAopContainer(SqlSession sqlSession) {
    MapperRegistry mapperRegistry = sqlSession.getConfiguration().getMapperRegistry();
    Collection<Class<?>> mappers = mapperRegistry.getMappers();
    for (Class c : mappers) {
      //c仅仅是一个接口,需要从sqlSession总获取代理类
      log.info("接口类c:{}", c);
      Object mapper = sqlSession.getMapper(c);
      log.info("代理类 mapper:{}", mapper);
      //Aop.inject(mapper);
      //AopManager.me().addMapping(c, mapper);
      AopManager.me().getAopFactory().inject(c,mapper);
      
      Object object = Aop.get(c);
      log.info("获取到的Object:{}",object);
    }
  
  }


异常日志

14:27:46.562 [main] INFO com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin - 获取sqlSession:org.apache.ibatis.session.defaults.DefaultSqlSession@13acb0d1
14:27:46.562 [main] INFO com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin - 接口类c:interface com.litongjava.jfinal.mybatis.mapper.SystemAdminMapper
14:27:46.564 [main] INFO com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin - 代理类 mapper:org.apache.ibatis.binding.MapperProxy@5db45159
三月 29, 2022 2:27:46 下午 com.jfinal.core.Config error
严重: Plugin start error: com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin. 
abstract class or interface can not be proxied
java.lang.IllegalArgumentException: abstract class or interface can not be proxied
	at com.jfinal.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:58)
	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:181)
	at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:91)
	at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65)
	at com.jfinal.aop.AopFactory.get(AopFactory.java:48)
	at com.jfinal.aop.Aop.get(Aop.java:93)
	at com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin.addMapperToAopContainer(MyBatisPlugin.java:75)
	at com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin.start(MyBatisPlugin.java:36)
	at com.jfinal.core.Config.startPlugins(Config.java:128)
	at com.jfinal.core.Config.configPluginWithOrder(Config.java:71)
	at com.jfinal.core.Config.configJFinal(Config.java:59)
	at com.jfinal.core.JFinal.init(JFinal.java:61)
	at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:64)
	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:591)
	at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:556)
	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:598)
	at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:287)
	at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:265)
	at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:158)
	at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:83)
	at com.litongjava.jfinal.mybatis.MybatisApp.main(MybatisApp.java:9)

java.lang.RuntimeException: Plugin start error: com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin. 
abstract class or interface can not be proxied
	at com.jfinal.core.Config.startPlugins(Config.java:137)
	at com.jfinal.core.Config.configPluginWithOrder(Config.java:71)
	at com.jfinal.core.Config.configJFinal(Config.java:59)
	at com.jfinal.core.JFinal.init(JFinal.java:61)
	at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:64)
	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:591)
	at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:556)
	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:598)
	at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:287)
	at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:265)
	at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:158)
	at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:83)
	at com.litongjava.jfinal.mybatis.MybatisApp.main(MybatisApp.java:9)
Caused by: java.lang.IllegalArgumentException: abstract class or interface can not be proxied
	at com.jfinal.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:58)
	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:181)
	at com.jfinal.aop.AopFactory.doGetSingleton(AopFactory.java:91)
	at com.jfinal.aop.AopFactory.doGet(AopFactory.java:65)
	at com.jfinal.aop.AopFactory.get(AopFactory.java:48)
	at com.jfinal.aop.Aop.get(Aop.java:93)
	at com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin.addMapperToAopContainer(MyBatisPlugin.java:75)
	at com.litongjava.jfinal.mybatis.plugin.MyBatisPlugin.start(MyBatisPlugin.java:36)
	at com.jfinal.core.Config.startPlugins(Config.java:128)
	... 16 more


评论区

热门反馈

扫码入社