spring-boot datasource profiles w/ application.properties

前端 未结 2 479
滥情空心
滥情空心 2021-02-19 07:40

Updated Question based upon feedback:

I have a spring-boot application that has three databases: H2 for integration testing, and Postgresql for

相关标签:
2条回答
  • 2021-02-19 08:27

    See section 21.3 of the Spring Boot documentation. This section describes how to define profile specific property files that use the format application-{profile}.properties. This can help you isolate properties on a per profile basis.

    0 讨论(0)
  • 2021-02-19 08:37

    You can annotate your tests adding @ActiveProfiles in the following way:

    @SpringApplicationConfiguration(classes = {Application.class, TestSpringConfiguration.class})
    @Test(groups = "integration")
    @ActiveProfiles("test")
    public class MyServiceTest extends AbstractTransactionalTestNGSpringContextTests {
    ...
       @Test 
       public void testSomething() {
          ...
       }
    } 
    

    I'm using TestNG but JUnint wouldn't be much different. You can also specify additional configuration as showed in the example above.

    That way you won't need to set the profile in build.gradle or launch configuration in IntelliJ

    0 讨论(0)
提交回复
热议问题