해당 이름의 빈이 클래스 경로 리소스 [경로]에 이미 정의되어 있으며 재정의가 사용되지 않도록 설정되었습니다.
Spring Data Elatic search(Transport Client 사용) 및 ESTemplate에 대한 Java 구성을 가지고 있습니다.다음을 제외한 일부 항목:
@Configuration
@EnableElasticsearchRepositories(basePackages = "subpackage-in-this-project")
@PropertySource("file:path-to-file")
public class ESConfig {
@Bean
ElasticsearchTemplate elasticsearchTemplate(Client client) {
return new ElasticsearchTemplate(client);
}
@Bean
Client client() {
// configuration of the ES client
}
}
그리고 다른 프로젝트에서 위의 것을 확장하는 구성을 가지고 있습니다.
@Configuration
@ComponentScan("package-prefix-that-matches-packages-in-both-projects")
@EnableElasticsearchRepositories(basePackages = "subpackage-in-this-project")
@PropertySource("file:same-path-to-file-as-in-the-config-above")
public class ExtendedESConfig extends ESConfig {
@Value("index-name")
private String indexName;
@Bean
public String indexName() {
return indexName;
}
}
프로젝트에 대한 종속성을 사용하는 세 번째 Spring Boot 응용 프로그램을 실행할 때ExtendedESConfig
2.0.5.REASE Spring Boot 버전에서 2.2.9.REASE로 업그레이드한 후 이러한 현상이 발생하기 시작한 이유를 이해할 수 없습니다.
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'elasticsearchTemplate', defined in class path resource [my/package/ESConfig.class], could not be registered. A bean with that name has already been defined in class path resource [my/other/package/ExtendedESConfig.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
2020-08-30 16:49:46 ERROR [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter:40 -
내 논평에서 중요한 언급:
안타깝게도 ES 구성을 작성하고 전체 인프라를 구축한 사람은 제가 아닙니다.
이 질문을 할 때 확장을 소유하지 않습니다.ESconfigor는 변경할 수 없습니다.
또는 다음 속성을 추가할 수 있습니다.application.properties
:
spring.main.allow-bean-definition-overriding=true
Bean을 재정의하는 기본 동작은 Spring Boot 2.1에서 비활성화되었습니다.Spring Boot 2.1 릴리스 정보
두 구성 클래스를 모두 소유하지 않거나 수정하지 않으려는 경우.상위 구성을 제외할 수 있습니다.SpringBootApplication
클래스 사용@ComponentScan
@SpringBootApplication
@ComponentScan(excludeFilters =
{@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ESConfig.class)})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
저도 비슷한 문제가 있었습니다.springSecurityFilterChain
메소드, 마이@Configuration
클래스입니다. 애플리케이션에서 이름을 가진 빈을 만들 수 없다고 합니다.springSecurityFilterChain
다른 곳에서 정의되었기 때문에(나의 경우, 당신의 경우와 마찬가지로 수정할 수 없는 Spring Security 패키지에서).
여기서 해결책을 찾았는데 단순히 사용자 지정 방법의 이름을 변경하는 것과 같았습니다.customFilterChain
그래서 그것은.
@Bean
public SecurityFilterChain springSecurityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf().disable()
// etc
}
대상:
@Bean
public SecurityFilterChain customFilterChain(HttpSecurity http) throws Exception {
return http
.csrf().disable()
// etc
}
놀랍게도 효과가 있었습니다.기사에 나와 있듯이, 스프링은 기본적으로 메소드의 이름을 사용하여 콩을 만듭니다.도움이 되길 바랍니다.
모듈에서 resources/application.properties를 찾아 다음과 같이 기록합니다.
spring.main.allow-bean-definition-overriding=true
도움이 됩니다. 콩 오버라이드 메커니즘을 활성화해야 합니다.
언급URL : https://stackoverflow.com/questions/63658346/a-bean-with-that-name-has-already-been-defined-in-class-path-resource-path-and
'programing' 카테고리의 다른 글
"ASIF()" 문을 쿼리하는 방법은 mariaDB? (0) | 2023.07.02 |
---|---|
ANSI JOIN 쿼리와 비 ANSI JOIN 쿼리의 성능이 다릅니까? (0) | 2023.07.02 |
정적 메서드는 스레드 안전합니까? (0) | 2023.07.02 |
mysql-connector-python 쿼리 스크립트가 작동하지 않지만 PHP에서만 작동합니다. (0) | 2023.07.02 |
openpyxl을 사용하여 특정 값의 셀이 포함된 행 찾기 (0) | 2023.07.02 |