提问者:小点点

application.yml 未在带有 Apache-CXF 的 Spring Boot 2 应用程序中加载


我刚开始使用apachecxf的springboot2。我正在尝试加载yml属性,但它返回了空对象。

当我使用spring.config.location=classpath:application.yml时,它正在正确加载。如果我没有给出任何东西,那么它就没有加载application.yml.

我把application.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

共1个答案

匿名用户

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

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

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

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