Intellij 에서 Spring Boot application.yml 또는 application.properties 를 못 읽어 올 때 (Resource 접근 안될 때)

Intellij 2019, Intellij 2020 버전에서

다음과 같이 Profile을 못 읽어 올 때가.. 솔직히 모든 경우 이랬다.

No active profile set, falling back to default profiles: default

위와 같이 application.properties나 application.yml에 profile을 active 한다고 해도 gradle의 bootrun이 아닌 intellij에서 제공하는 Run 기능으로 진행 할 경우 위와 같이 이를 인식 하지 못한다.

정확히 말하자면 Run으로 Spring Boot를 실행하면 application.properties가 존재하는

  • resources 디렉토리 자체를 인식 하지 못하는 것이다.

아래 보면 bootRun을 Gradle을 통해서 진행할 경우 문제가 없다.

어떤 차이일까?

그건 .idea 라고 하는 intellij 설정 프로그램이 Spring Boot의 환경을 잘 인식 하지 못해서 이다.

https://youtrack.jetbrains.com/issue/IDEA-221673?_ga=2.153992433.879311547.1623645922-711668597.1620620947 

해결 방법은

Support feedback:

1)  Generate a new Spring Webflux application, using "Gradle Project"
2)  Add the "LoggingController" as a very simple REST endpoint
3)  Add "logging.level.com.example=debug" to application.properties
4)  When this application is run, none of the debug-level statements are logged to the console
5)  When this application is rebuilt, I get the 3 warnings (not errors) about not being able to generate modules
6)  If I then delete the .idea folder and import the project from build.gradle...
6a)  The debug statements are logged to the console when the application is run
6b)  A request to "rebuild" does not result in the warnings being generated/displayed

이렇게 제안이 되고 있다.

가장 확실한 방법은 .idea를 삭제하는 것이다.

이렇게 삭제 하고 프로젝트를 다시 실행 후 Gradle build를 다시 하면

짜잔...

resources 디렉토리를 읽어올 수 있다.

몇 개월 간 해결 방법을 찾았었는데 ㅠㅠ 드디어 찾았다 행복~

혹시 진짜 spring profile 자체를 어떻게 사용하는지 모르면 다음 링크를 참고하면 된다.

2021.06.16 - [JAVA] - Spring Boot Profile 설정

728x90
반응형