Load different application.yml in SpringBoot Test

前端 未结 11 1156
天涯浪人
天涯浪人 2020-11-30 22:09

I\'m using a spring boot app which runs my src/main/resources/config/application.yml.

When I run my test case by :

@RunWith(SpringJUnit4ClassRunner.c         


        
11条回答
  •  难免孤独
    2020-11-30 22:52

    Lu55 Option 1 how to...

    Add test only application.yml inside a seperated resources folder.

    ├── main
    │   ├── java
    │   └── resources
    │       ├── application.yml
    └── test
        ├── java
        └── resources
            └── application.yml
    

    In this project structure the application.yml under main is loaded if the code under main is running, the application.yml under test is used in a test.

    To setup this structure add a new Package folder test/recources if not present.

    Eclipse right click on your project -> Properties -> Java Build Path -> Source Tab -> (Dialog ont the rigth side) "Add Folder ..."

    Inside Source Folder Selection -> mark test -> click on "Create New Folder ..." button -> type "resources" inside the Textfeld -> Click the "Finish" button.

    After pushing the "Finisch" button you can see the sourcefolder {projectname}/src/test/recources (new)

    Optional: Arrange folder sequence for the Project Explorer view. Klick on Order and Export Tab mark and move {projectname}/src/test/recources to bottom. Apply and Close

    !!! Clean up Project !!!
    Eclipse -> Project -> Clean ...

    Now there is a separated yaml for test and the main application.

提交回复
热议问题