nebula-contrib / ngbatis

NGBATIS is a database ORM framework base NebulaGraph + spring-boot, which takes advantage of the mybatis’ fashion development, including some de-factor operations in single table and vertex-edge, like mybatis-plus. NGBATIS 是一款针对 NebulaGraph + Springboot 的数据库 ORM 框架。借鉴于 MyBatis 的使用习惯进行开发。https://graph-cn.github.io/ngbatis-docs/
https://nebula-contrib.github.io/ngbatis/
Apache License 2.0
130 stars 42 forks source link

Consider defining a bean of type 'com.*.mapper.TagMapper' in your configuration. #111

Closed ZhangJinzhaoGit closed 1 year ago

ZhangJinzhaoGit commented 1 year ago

你好,麻烦问一下,我的项目启动不起来,报这个错误, image image image

麻烦帮忙看看,谢谢

CorvusYe commented 1 year ago

可以看下xml开头,xml里面的namespace需要写完整包名,不支持通配符*

ZhangJinzhaoGit commented 1 year ago

image 我是这么写的 image

CorvusYe commented 1 year ago

这么写没问题啊,有没有其他文件

ZhangJinzhaoGit commented 1 year ago

没有,只有这一个mapper,我用master分支里面demo把数据库地址换成我的启动也是报这个,和spring版本有关系吗? image

CorvusYe commented 1 year ago

Springboot 的启动类需要加包扫描:@SpringBootApplication(scanBasePackages = {"org.nebula.contrib", "项目包名"})

CorvusYe commented 1 year ago

会不会是扫描包没有加

ZhangJinzhaoGit commented 1 year ago

image image 我用demo启动也报这个

CorvusYe commented 1 year ago

我看下哈,刚刚没在电脑边上

CorvusYe commented 1 year ago

1671542494929 方便在这个方法断点看看吗,这里是注册 bean 的地方

ZhangJinzhaoGit commented 1 year ago

image 我点启动后连这个断点都没有进。。

CorvusYe commented 1 year ago

是让人挺费解的... 如果没有 Swagger2Configuration 呢

ZhangJinzhaoGit commented 1 year ago

也不行。。。

CorvusYe commented 1 year ago

image 试下这个Springboot的入口能不能进断点。 JDK是什么版本。

ZhangJinzhaoGit commented 1 year ago

JDK11 image

CorvusYe commented 1 year ago

这里面也没啥条件判断了,通过这里的addBeanFactoryPostProcessor进到 spring ioc 容器,再到 NgbatisBeanFactoryPostProcessor#postProcessBeanFactory 方法,再到 NgbatisBeanFactoryPostProcessor#registerBean 基本上是顺序执行... 一个断点能进一个断点不能进,源代码还一样,一时间我也没想通... 还得再花点时间看看哈,不好意思哈~

CorvusYe commented 1 year ago

当 SpringApplication run 方法被调起:

sequenceDiagram
NgbatisDemoApplication#main->>SpringApplication: run
SpringApplication->>SpringApplication: prepareContext
Note over SpringApplication: prepareContext 方法内调用 applyInitializers
SpringApplication->>SpringApplication: applyInitializers
      loop initializers
          alt  initializer is NgbatisContextInitializer
              SpringApplication->>NgbatisContextInitializer:  initialize
              NgbatisContextInitializer->>AbstractApplicationContext: addBeanFactoryPostProcessor( NgbatisBeanFactoryPostProcessor )
          end
      end
SpringApplication->>SpringApplication: refreshContext
Note over SpringApplication: refreshContext 方法内调用 refresh
SpringApplication->>SpringApplication: refresh
Note over SpringApplication: refresh 方法内调用 refresh
SpringApplication->>AbstractApplicationContext: refresh
AbstractApplicationContext->>AbstractApplicationContext: invokeBeanFactoryPostProcessors
Note over AbstractApplicationContext: invokeBeanFactoryPostProcessors 方法内调用 invokeBeanFactoryPostProcessors
AbstractApplicationContext->>PostProcessorRegistrationDelegate: invokeBeanFactoryPostProcessors
PostProcessorRegistrationDelegate->>PostProcessorRegistrationDelegate: invokeBeanFactoryPostProcessors(postProcessors, beanFactory)
      loop 
          alt  processor is NgbatisBeanFactoryPostProcessor
            PostProcessorRegistrationDelegate->>NgbatisBeanFactoryPostProcessor:  postProcessBeanFactory
            Note over NgbatisBeanFactoryPostProcessor: postProcessBeanFactory 方法内调用 mapperContext
            NgbatisBeanFactoryPostProcessor->>NgbatisBeanFactoryPostProcessor: mapperContext
            Note over NgbatisBeanFactoryPostProcessor: mapperContext 方法内调用 registerBean
            NgbatisBeanFactoryPostProcessor->>NgbatisBeanFactoryPostProcessor: registerBean
          end
      end

可以帮我跟下整个过程是否符合上面的过程吗, 我这边正常,所以...实在是想不到哪个环境的问题导致的 registerBean 断点进不来。 感谢感谢~

其中:invokeBeanFactoryPostProcessors 断点会进两次,第二次的时候 postProcessors 才会包含NgbatisBeanFactoryPostProcessor

ZhangJinzhaoGit commented 1 year ago

解决了,我傻了。。 我看那个源码里面有个if的判断是nebula.hosts,读到这个才会去走,我看了下我的,我写的是nebula.address,改了之后就好了。 感谢!

CorvusYe commented 1 year ago

那个是为了兼容nacos的判断,避免加载两次导致其中一次读取不到配置信息