Skip to content

NPE occurred when using EnableApolloConfig with Spring 3.1.1 #4178

@nobodyiam

Description

@nobodyiam
  • I have checked the discussions
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Describe the bug
When using @EnableApolloConfig with Spring 3.1.1, NullPointerException will occur.

To Reproduce
Steps to reproduce the behavior:

  1. Mark a configuration class with @EnableApolloConfig
@Configuration
@EnableApolloConfig(value = "application", order = 10)
public class AppConfig {
  @Bean
  public NormalBean normalBean(@Value("${batch:100}") int batch) {
    NormalBean bean = new NormalBean();
    bean.setBatch(batch);
    return bean;
  }
}
  1. Run the application with Spring version 3.1.1
  2. NullPointerException will occur
Exception in thread "main" java.lang.NullPointerException
	at com.ctrip.framework.apollo.spring.spi.DefaultApolloConfigRegistrarHelper.resolveNamespaces(DefaultApolloConfigRegistrarHelper.java:52)
	at com.ctrip.framework.apollo.spring.spi.DefaultApolloConfigRegistrarHelper.registerBeanDefinitions(DefaultApolloConfigRegistrarHelper.java:29)
	at com.ctrip.framework.apollo.spring.annotation.ApolloConfigRegistrar.registerBeanDefinitions(ApolloConfigRegistrar.java:20)
	at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:331)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:228)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:126)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:263)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:203)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:617)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
	at com.ctrip.framework.apollo.demo.spring.AnnotationApplication.main(AnnotationApplication.java:12)

Expected behavior
The application should work well

Screenshots
If applicable, add screenshots to help explain your problem.

Additional Details & Logs

  • Version
  • Error logs
  • Configuration
  • Platform and Operating System

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/clientapollo-clientbugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions