Immutable Configuration Properties
์คํ๋ง ๋ถํธ 2.2 ๋ถํฐ @ConstructorBinding์ ์ฌ์ฉํ์ฌ ์์ฑ์๋ฅผ ๊ฐ์ง์ง ์๋ ํด๋์ค๋ฅผ ์์ฑํ ์ ์์ผ๋ฉฐ ์คํ๋ง ๋ถํธ 3.0 ๋ถํฐ๋ @ConstructorBinding ์ ์ธ ๋์์ด ์์ฑ์๋ก ์ถ์๋์ด ์๋์ ๊ฐ์ด ์คํ๋ง ๋ถํธ 3 ์์๋ ์์ฑ์๊ฐ ํ๋์ธ ๊ฒฝ์ฐ์๋ ๊ตณ์ด ์ง์ ํ์ง ์๋๋ค.
Spring Boot 2.7@Getter @RequiredArgsConstructor @ConstructorBinding @ConfigurationProperties(prefix = "feature") public class FeatureProperties { private final boolean enabled; } @ConfigurationPropertiesScan @EnableConfigurationProperties @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Spring Boot 3.2@Getter @RequiredArgsConstructor @ConfigurationProperties(prefix = "feature") public class FeatureProperties { private final boolean enabled; } @ConfigurationPropertiesScan @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Parameter Name Discovery from Spring Boot 3.1
Ensure that your compiler is configured to use the โ-parametersโ flag.
์คํ๋ง ๋ถํธ 3.2 ์์ ์์ฑ์ ๋ฐ์ธ๋ฉ์ ํตํด Immutable Configuration Properties๋ฅผ ๋ง๋๋ ค๋ ๊ฒฝ์ฐ ์์ ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์๋ค. ์ ์ค๋ฅ ๋ฉ์์ง๋ MissingParametersFailureAnalyzer ์ ์ํด ์ถ๋ ฅ๋๋ ๊ฒ์ผ๋ก ์คํ๋ง ๋ถํธ 3.2 ์์ ์์กดํ๋ ์คํ๋ง ํ๋ ์์ํฌ ๋ฒ์ ์์ ๋ฐ์ดํธ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ํ๋ผ๋ฏธํฐ ์ด๋ฆ์ ์ถ๋ก ํด์ค๋ LocalVariableTableParameterNameDiscoverer ํด๋์ค๊ฐ ์ ๊ฑฐ๋์ด ํ๋ผ๋ฏธํฐ ์ด๋ฆ์ผ๋ก ์ถ๋ก ํ๋ ๋์์ ํด๋นํ๋ ์์ฑ์ ๋ฐ์ธ๋ฉ์ ์ํด StandardReflectionParameterNameDiscoverer ๊ฐ ์ฌ์ฉ๋ ์ ์๋๋ก ์ปดํ์ผ๋ฌ์ ๋ํด -parameters
์ต์
์ ์ง์ ํด์ผํ๋ค.
build.gradle// NOTE: https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention tasks.withType(JavaCompile).configureEach { options.compilerArgs.add("-parameters") }
๋ง์ฝ, ์ธํ
๋ฆฌ์ ์ด๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๊ทธ๋๋ค์ด ์๋ Build and run using ์ต์
์ผ๋ก Intellij IDEA๋ฅผ ์ง์ ํ๋ ํธ์ด๋ผ๋ฉด ์๋ฐ ์ปดํ์ผ๋ฌ ์ต์
์ -parameters
์ต์
์ ๋ณ๋๋ก ์ค์ ํด์ผํ๋ค. ์๋ฐ ์ปดํ์ผ๋ฌ ์ต์
์ -paramters
ํ๋๊ทธ๋ฅผ ์ค์ ํ์์๋ ํ๋ผ๋ฏธํฐ ์ด๋ฆ ์ถ๋ก ์ ์ํ ์ค๋ฅ๊ฐ ์ถ๋ ฅ๋๋ค๋ฉด ์ธํ
๋ฆฌ์ ์ด๊ฐ ์์ฑํ out
ํด๋๋ฅผ ์ญ์ ํ๊ณ ๋ค์ ๋น๋๋ฅผ ์ํํด๋ณด๋๋ก ํ์.
Spring Boot 3.2 ์์ Immutable Configuration Properties ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด ์๊ฐ์ง๋ ๋ชปํ ์ฝ์ง์ ํ์ต๋๋ค.