본문 바로가기
Spring

Spring Framework (8) - Bill of Materials을 활용한 Spring Framework 버전 관리

by 이도현 2021. 5. 19.

    

    스프링 프레임워크에서 pom.xml에서 의존성 주입을 하고 사용을 해보면 버전 문제로 정상적으로 동작하지 않는 경우가 너무 많이 발생한다. BOM 설정으로 이러한 버전 관리를 위임하는 방식이 있어 소개한다. 구체적인 설명은 아래 참조를 보면 될 것 같다. 일단 기존 설정에서 수정되는 부분은 

<dependencyManagement>

<!-- Spring Framework (Bill of Materials) -->

<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-framework-bom</artifactId>

<version>${org.springframework-version}</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

이 부분을 추가하는 것이다. project 태그 안의 어느 곳에 위치시키면 된다. 이후 groupId가 org.springframework으로 되어 있는 것의 버전을 모두 제거해주면 된다. 

<!-- Spring Context -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<exclusions>

<!-- Exclude Commons Logging in favor of SLF4j -->

<exclusion>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

</dependency>

 

<!-- Spring TestContext Framework -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId>

<scope>test</scope>

</dependency>

 

    이와 같이 수정하면 될 것 같다. 이후 프로젝트를 maven update를 해주면 된다. 

참조

https://www.baeldung.com/spring-maven-bom

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html