BeanInstantiationException in Spring Boot with local @Configure and XML Configure for 3rd party

Viewed 38

I have a Spring Boot app with my own GlobalConfig class.

@Getter
@Setter
@Configuration
@PropertySource("application.properties")
public class GlobalConfig {

    @Value("${kafka.bootstrap.servers}")
    private String BOOTSTRAP_SERVERS;

    @Value("${kafka.schema.registry}")
    private String SCHEMA_REGISTRY;

.. etc

This app includes a 3rd party Spring Boot app that uses an XML config. The 3rd party app creates its own ApplicationContext using an XML file in the main app's resources directory.

The problem is, during this 3rd party ApplicationContext's refresh(), it references my local GlobalConfig and complains that it can't resolve the placeholders. And then it fails to instantiate.

So, how do I remove my GlobalConfig from the 3rd party's AppContext's bean factory so this exception isn't thrown?

o.s.c.s.ClassPathXmlApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'broadcast' defined in class path resource [context/broadcast.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.foo.ThirdPartyBean]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'bootstrap.servers' in value "${kafka.bootstrap.servers}"

1 Answers

just try to import xml file in GlobalConfig

@ImportResource("classpath:context/broadcast.xml")
Related