【问题标题】:application.yml is not loading in spring boot 2 application with apache-cxfapplication.yml 未使用 apache-cxf 在 Spring Boot 2 应用程序中加载
【发布时间】:2020-07-25 21:37:58
【问题描述】:

我是使用 apache-cxf 的 spring boot2 新手。我正在尝试加载 yml 属性,但它返回的是空对象。

当我使用 spring.config.location=classpath:application.yml 时,它会正确加载。如果我什么都不提供,那么它就不会加载 application.yml。

我把applicatin.yml是src\main\resources 这是我的示例代码:


    @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

【问题讨论】:

  • 我发现的一个观察结果是,如果我从 tomcat catalina_opts 中删除 -Dspring.config.location 属性,则应用程序正在加载 application.yml。我要求我的应用程序应该从外部位置读取 yml 文件。我仍在调查解决方案。
  • 我成功地得到了解决方案。如果我们使用 -Dspring.config.location,那么应用程序将不会考虑除了 -Dspring.config.location 中提供的文件之外的任何其他 yml 文件。如果我们想从外部文件夹加载 yml 文件,那么我们必须使用属性 "-Dspring.config.additional-location" 。在这个属性中,我们需要提供 yml 文件。示例 ``` 设置 CATALINA_OPTS=-Dspring.config.additional-location=file:${catalina.base}/private/sensitive.yml,file:${catalina.base}/public/override.yml

标签: cxf spring-boot-2


【解决方案1】:

由于我在我的 tomcat setenv.bat 属性中配置了 -Dspring.config.location 属性,因此 Spring Boot 仅加载那些 yml 文件。

如果你想从外部文件夹加载文件,那么我们必须使用新属性

-Dspring.config.additional-location 而不是 -Dspring.config.location

更改上述属性后,它开始工作。

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2017-07-04
    相关资源
    最近更新 更多