Spring Boot bean自动配置命令

时间:2018-06-16 08:06:56

标签: java spring spring-boot javabeans

我有一个包,包中的A类使用@ConfigurationConditionalOnBean(B.class)进行注释,并由spring.factories加载;

在其他软件包的spring bean xml中,有一个工厂Bean C,它自动装配一个bean B;

当我启动服务器时,我找到了bean B和C,但是没有注册bean A.

调试日志显示bean A为负匹配,但spring找到Bean B,日志就像:

[DEBUG] 20180615 17:19:23.200 [localhost-startStop-1] ConfigurationClassBeanDefinitionReader - Registered bean definition for imported class 'A'
[DEBUG] 20180615 17:19:23.525 [localhost-startStop-1] ConfigurationClassEnhancer - Successfully enhanced A; enhanced class name is: A$$EnhancerBySpringCGLIB$$590152cc
[DEBUG] 20180615 17:19:23.525 [localhost-startStop-1] ConfigurationClassPostProcessor - Replacing bean definition 'A' existing class 'A' with enhanced class 'A$$EnhancerBySpringCGLIB$$590152cc'
[DEBUG] 20180615 17:19:23.586 [localhost-startStop-1] GenericScope - Generating bean factory id from names: [A]
[DEBUG] 20180615 17:20:11.825 [localhost-startStop-1] BeanNameUrlHandlerMapping - Rejected bean name 'A': no URL paths identified
[DEBUG] 20180615 17:20:13.574 [localhost-startStop-1] DefaultListableBeanFactory - Creating shared instance of singleton bean 'A'
[DEBUG] 20180615 17:20:13.574 [localhost-startStop-1] DefaultListableBeanFactory - Creating instance of bean 'A'
[DEBUG] 20180615 17:20:13.574 [localhost-startStop-1] DefaultListableBeanFactory - Eagerly caching bean 'A' to allow for resolving potential circular references
[DEBUG] 20180615 17:20:13.609 [localhost-startStop-1] DefaultListableBeanFactory - Finished creating instance of bean 'A'
report
A:
      Did not match:
         - @ConditionalOnBean (types: B; SearchStrategy: all) did not find any beans (OnBeanCondition)
      Matched:
         - @ConditionalOnBean (types: B; SearchStrategy: all) found bean 'defaultB' (OnBeanCondition)

我想知道:

  1. 命令springboot注册bean;
  2. 为什么报告显示"没有找到任何豆子"和#34;找到豆子"同时?

0 个答案:

没有答案