0

I am new to spring boot2 with apache-cxf. I am trying to load the yml properties, but it is returning empty object.

When I am using spring.config.location=classpath:application.yml, then it is loading properly. If I don't give anything, then it is not loading the application.yml.

I put the applicatin.yml is src\main\resources Here is my sample code:


    @SpringBootApplication
    @ComponentScan(basePackages = {"com.ironmountain"})
    @ConfigurationPropertiesScan(basePackages = {"com.ironmountain"})
    @EnableCaching

    public class Boot2Main extends SpringBootServletInitializer {

        private static final IrmLogger IRMLOGGER = IrmLoggerFactory.getIrmLogger(Boot2Main.class);

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {    
            return application.sources(Boot2Main.class);
        }

        public static void main(String[] args) {
            IRMLOGGER.debug("Starting Customer Facing web app");
            SpringApplication.run(Boot2Main.class, args);
        }
    }


Jaxrs configuration:

 @Bean
public JAXRSServerFactoryBean getJAXRSServerFactoryBean() {
    JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
    factoryBean.setBus(bus);
    factoryBean.setProviders(getProviders());
    factoryBean.setServiceBeans(getJaxrsResources());
    factoryBean.setInInterceptors(getInInterceptors());
    factoryBean.setFeatures(getFeatures());
    factoryBean.setOutInterceptors(getOutInterceptors());
    factoryBean.setOutFaultInterceptors(getOutInterceptors());        
    factoryBean.setAddress("/");
    irmLogger.debug("JAX-RS Server Factory Beans added");
    return factoryBean;
}

apache-cxf version =3.3.7
Spring boot version = 2.3.1
external tomcat = 9.0.36
Appreciate your help
Dharisi Suresh
  • 150
  • 2
  • 14
  • One observation I found is, If I remove -Dspring.config.location property from tomcat catalina_opts , then application is loading the application.yml. I have a requirement that my application should read yml files from external location. I am still investigation for the solutions. – Dharisi Suresh Jul 25 '20 at 22:35
  • Successfully I got the solution. If we use -Dspring.config.location, then application will not consider any other yml files apart from provided files in -Dspring.config.location. If we want to load yml files from external folders, then we have to use the property "-Dspring.config.additional-location" . In this property we need to provide the yml files. Example ``` set CATALINA_OPTS=-Dspring.config.additional-location=file:${catalina.base}/private/sensitive.yml,file:${catalina.base}/public/override.yml – Dharisi Suresh Jul 25 '20 at 22:56

1 Answers1

0

Since I have -Dspring.config.location property configured in my tomcat setenv.bat properties, spring boot is loading only those yml files.

If you want to load files from external folder, then we have to use new property

-Dspring.config.additional-location instead of -Dspring.config.location

After changing above property, then it started working.

Dharisi Suresh
  • 150
  • 2
  • 14