Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目启动报WARN #2328

Closed
liuzedong opened this issue Jun 12, 2019 · 8 comments
Closed

项目启动报WARN #2328

liuzedong opened this issue Jun 12, 2019 · 8 comments

Comments

@liuzedong
Copy link

日志

2019-06-12 12:04:59.670|/|WARN |main|o.s.b.c.p.PropertySourcesDeducer|Multiple PropertySourcesPlaceholderConfigurer beans registered [propertySourcesPlaceholderConfigurer, org.springframework.context.support.PropertySourcesPlaceholderConfigurer], falling back to Environment

Apollo Client => ConfigPropertySourcesProcessor

image

Spring boot => org.springframework.boot.context.properties.PropertySourcesDeducer

image

这个能修复下吗? 项目使用 sentry, 每次项目启动 都收到 邮件提醒。

@nobodyiam
Copy link
Member

apollo在注册PropertySourcesPlaceholderConfigurer时会检查是否已经存在这个bean的,如果不存在才会添加。

建议在报warning的地方加个断点看下另外一个bean是谁加进来的。

@liuzedong
Copy link
Author

PropertySourcesPlaceholderConfigurer 这个bean是在,spring-boot-autoconfigure.jar : org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
中加载进来的,
image

@nobodyiam
Copy link
Member

我跑了SpringBootSampleApplication这个sample,貌似没能复现这个问题?

@liuzedong
Copy link
Author

异常:2019-06-27 10:27:31.108 INFO 7255 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-06-27 10:27:31.533 INFO 7255 --- [ main] o.s.c.a.ConfigurationClassPostProcessor : Cannot enhance @configuration bean definition 'com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2019-06-27 10:27:33.731 WARN 7255 --- [ main] o.s.b.c.p.PropertySourcesDeducer : Multiple PropertySourcesPlaceholderConfigurer beans registered [propertySourcesPlaceholderConfigurer, org.springframework.context.support.PropertySourcesPlaceholderConfigurer], falling back to Environment
2019-06-27 10:27:33.969 INFO 7255 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.017 seconds (JVM running for 5.27)

SpringBoot使用https://start.spring.io/ 创建最简化项目

image
image

demo地址

https://github.com/liuzedong/apollo-demo

@nobodyiam
Copy link
Member

确实能重现这个问题,看了一下,如果在DemoApplication上打上注解EnableApolloConfig就不会出现这个WARN日志,尚未仔细定位区别在哪儿

@SpringBootApplication
@EnableApolloConfig
public class DemoApplication {
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

@liuyukuai
Copy link

liuyukuai commented Jul 7, 2019

  • 第一次加载是org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration加载而来,beanName是"propertySourcesPlaceholderConfigurer"

  • Apollo Client => ConfigPropertySourcesProcessor这个类是通过类的全路径判断的,所以判断不出来是否加载了

public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName, Class<?> beanClass, Map<String, Object> extraPropertyValues) {
       // 这里是否能通过beanClass判断?
      if (registry.containsBeanDefinition(beanName)) {
            return false;
        } else {
            String[] candidates = registry.getBeanDefinitionNames();
            String[] arr$ = candidates;
            int len$ = candidates.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String candidate = arr$[i$];
                BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
                if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
                    return false;
                }
            }

            BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(beanClass).getBeanDefinition();
            if (extraPropertyValues != null) {
                Iterator i$ = extraPropertyValues.entrySet().iterator();

                while(i$.hasNext()) {
                    Entry<String, Object> entry = (Entry)i$.next();
                    beanDefinition.getPropertyValues().add((String)entry.getKey(), entry.getValue());
                }
            }

            registry.registerBeanDefinition(beanName, beanDefinition);
            return true;
        }
    }
  • 加上@EnableApolloConfig这个确实就不报了,这个有定位到原因吗?

@stale
Copy link

stale bot commented Nov 30, 2019

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in 14 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 30, 2019
@stale
Copy link

stale bot commented Dec 14, 2019

This issue has been automatically closed because it has not had activity in the last 14 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.

@stale stale bot closed this as completed Dec 14, 2019
@nobodyiam nobodyiam reopened this Mar 28, 2020
lonre added a commit to lonre/apollo that referenced this issue Aug 1, 2021
case: beanDefinition of the bean defined in Configuration annotated class
in this case, the `beanDefinition.getBeanClassName()` and `beanClass.getName()` is not match
lonre added a commit to lonre/apollo that referenced this issue Dec 17, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.

related to apolloconfig#2328 apolloconfig#3865
@lonre lonre mentioned this issue Dec 17, 2021
5 tasks
lonre added a commit to lonre/apollo that referenced this issue Dec 18, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.

related to apolloconfig#2328 apolloconfig#3865
nobodyiam added a commit that referenced this issue Dec 19, 2021
* Fix #4152
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.

related to #2328 #3865

* Update CHANGES.md

Co-authored-by: Jason Song <[email protected]>
lonre added a commit to lonre/apollo that referenced this issue Dec 21, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to apolloconfig#2328 apolloconfig#3865 apolloconfig#4161 apolloconfig#4164
@lonre lonre mentioned this issue Dec 21, 2021
5 tasks
lonre added a commit to lonre/apollo that referenced this issue Dec 23, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to apolloconfig#2328 apolloconfig#3865 apolloconfig#4161 apolloconfig#4164
nobodyiam pushed a commit that referenced this issue Dec 24, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to #2328 #3865 #4161 #4164
lonre added a commit to lonre/apollo that referenced this issue Dec 24, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to apolloconfig#2328 apolloconfig#3865 apolloconfig#4161 apolloconfig#4164
@lonre lonre mentioned this issue Dec 24, 2021
5 tasks
nobodyiam pushed a commit that referenced this issue Dec 25, 2021
`beanFactory.isTypeMatch` may lead to the initialization of FactoryBean,
dubbo consumer is a ReferenceBean which implements FactoryBean.
support spring 3

related to #2328 #3865 #4161 #4164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants