spring-boot datasource profiles w/ application.properties

前端 未结 2 484
滥情空心
滥情空心 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条回答
  •  萌比男神i
    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

提交回复
热议问题