반응형
Spring boot에서 "ConditionalOnProperty is exclusive"를 어떻게 수정합니까?
코드를 고려합니다.
package com.hellokoding.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
@Bean
@ConditionalOnProperty(prefix = "config.prefix", name = "name", value = "SOMEVALUE", matchIfMissing = true)
public BeanOne beanOne() {
System.out.println("ok");
return new BeanOne();
}
@Bean
@ConditionalOnProperty(prefix = "config.prefix", name = "name", value = "OTHERVALUE")
public BeanTwo beanTwo() {
System.out.println("ok");
return new BeanTwo();
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(WebApplication.class, args);
}
}
여기 코드가 있는 Git repo가 있습니다.스프링 부트를 시작할 때 예외가 발생했습니다.
java.lang.IllegalStateException: Error processing condition on com.hellokoding.springboot.WebApplication.beanOne
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:178) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:140) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:333) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at com.hellokoding.springboot.WebApplication.main(WebApplication.java:32) [classes/:na]
Caused by: java.lang.IllegalStateException: The name and value attributes of @ConditionalOnProperty are exclusive
at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getNames(OnPropertyCondition.java:152) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.determineOutcome(OnPropertyCondition.java:106) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.findNoMatchOutcomes(OnPropertyCondition.java:91) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getMatchOutcome(OnPropertyCondition.java:53) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
... 17 common frames omitted
뭐가 잘못됐습니까?OO 속성이 존재하며 구문은 매우 단순하며 예제와 같습니다.
추신. 많은 스프링 부트 구성에 접두사와 값이 있는 동일한 조건부 On 속성이 있기 때문에 이 모든 것이 매우 이상하게 보입니다. 이러한 구성에 버그가 있으면 작동하지 않습니다.
그value
매개 변수는 별칭으로 지정됨name
이 오류로 이어집니다. 즉, 사실상 동일한 매개 변수입니다.
스왑할 수 있습니다.value
로.havingValue
@ConditionalOnProperty(prefix = "config.prefix", name = "name", havingValue = "OTHERVALUE")
@ConditionalOnProperty(prefix = "config.prefix", name = "name", havingValue = "SOMEVALUE", matchIfMissing = true)
언급URL : https://stackoverflow.com/questions/52949152/how-fix-conditionalonproperty-are-exclusive-in-spring-boot
반응형
'sourcetip' 카테고리의 다른 글
인덱스 rowid BATCHED에 의한 테이블 액세스와 인덱스 rowid에 의한 테이블 액세스 간의 차이 (0) | 2023.08.06 |
---|---|
모듈 __file__ 특성이 절대적입니까, 상대적입니까? (0) | 2023.08.06 |
AJAX 요청 후 위쪽으로 스크롤 중지 (0) | 2023.08.01 |
선형 레이아웃에서 단추 가운데 맞춤 (0) | 2023.08.01 |
시스템.인수예외:테이블 형식 매개 변수에는 올바른 형식 이름이 있어야 합니다. (0) | 2023.08.01 |