当前位置: 首页> 健康> 知识 > 为企业推广_常州建设工程交易网_智能网站排名优化_优化seo厂家

为企业推广_常州建设工程交易网_智能网站排名优化_优化seo厂家

时间:2025/7/11 22:59:00来源:https://blog.csdn.net/qq_58159506/article/details/146765129 浏览次数:0次
为企业推广_常州建设工程交易网_智能网站排名优化_优化seo厂家

1.报错

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'articlesRepository' for bean class [com.dragon.springboot3vue3.mapper.ArticlesRepository] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean]

2.报错原因

@MapperScan 是 MyBatis 的注解,扫描 Mapper 接口;

@EnableElasticsearchRepositories 是 Spring Data 的注解,扫描 Elasticsearch Repository;

当两者扫描同一个包路径时,会导致 Bean 定义冲突。

3.解决方案

3.1 (推荐)分离包路径,启动类添加 @MapperScan,@EnableElasticsearchRepositories

@SpringBootApplication
@MapperScan("com.dragon.springboot3vue3.mapper")       // MyBatis Mapper
@EnableElasticsearchRepositories("com.dragon.springboot3vue3.es.repository") // ES Repository
public class Springboot3Vue3Application {public static void main(String[] args) {SpringApplication.run(Springboot3Vue3Application.class, args);}
}

调整目录结构

src/main/java/com/dragon/springboot3vue3/

├── mapper/  # MyBatis Mapper 接口
│   
└── es/
    ├── repository/ # ES Repository 接口
    └── model/      # ES 文档实体

3.2 启动类完全移除注解,让 Spring Boot 自动扫描。但是 MyBatis 的每个Mapper层必须添加 @Mapper 注解

@SpringBootApplication
// @MapperScan("com.dragon.springboot3vue3.mapper")       // 删除 MyBatis MapperScan
// @EnableElasticsearchRepositories("com.dragon.springboot3vue3.es.repository") // 删除 ES Repository
public class Springboot3Vue3Application {public static void main(String[] args) {SpringApplication.run(Springboot3Vue3Application.class, args);}
}

 

关键字:为企业推广_常州建设工程交易网_智能网站排名优化_优化seo厂家

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: