Skip to content

์Šคํ”„๋ง ๋ถ€ํŠธ 2.2 ๋ถ€ํ„ฐ @ConstructorBinding์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์„ฑ์ž๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๋Š” ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์Šคํ”„๋ง ๋ถ€ํŠธ 3.0 ๋ถ€ํ„ฐ๋Š” @ConstructorBinding ์„ ์–ธ ๋Œ€์ƒ์ด ์ƒ์„ฑ์ž๋กœ ์ถ•์†Œ๋˜์–ด ์•„๋ž˜์™€ ๊ฐ™์ด ์Šคํ”„๋ง ๋ถ€ํŠธ 3 ์—์„œ๋Š” ์ƒ์„ฑ์ž๊ฐ€ ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ์—๋Š” ๊ตณ์ด ์ง€์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค.

java
@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);
    }
}
java
@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 ์˜ต์…˜์„ ์ง€์ •ํ•ด์•ผํ•œ๋‹ค.

groovy
// 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 ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ƒ๊ฐ์ง€๋„ ๋ชปํ•œ ์‚ฝ์งˆ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ  ๋งํฌ โ€‹

Released under the MIT License.