有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (4) 个答案

  1. # 1 楼答案

    看来你不能。既然春天本身也不能

    In the sample above we have configured the service.message for the test using the default attribute of the @SpringBootTest annotation. It is not advisable to put application.properties in a library because there might be a clash at runtime in the application that uses it (only one application.properties is ever loaded from the classpath). You could put application.properties in the test classpath, but not include it in the jar, for instance by placing it in src/test/resources.

  2. # 2 楼答案

    取决于库属性文件指定属性的方式。如果首先从环境/系统中查找属性,则可以在代码中重写。如果是硬编码,则不是。 例如:

    prop=${ENV_VAR:abc}
    

    您可以在代码中设置ENV_VAR环境变量或env-var系统变量来覆盖prop的值。如果没有,将使用默认值abc

  3. # 3 楼答案

    不要添加应用程序。属性文件到库中。它可能会引起很多问题。如果要设置默认属性,请执行以下操作:

    @ConfigurationProperties("foo")
    public class FooConfig {
    
        private int bar = 999;
    
        // getter / setter
    
    }
    

    每个应用程序都应该在自己的应用程序中为自己配置库值。属性文件