在春季从另一个项目中查找存储库

我有多个使用 spring 2.1.3 的项目,并希望让他们共享一些实体以及他们的存储库。


示例存储库:


package com.my.otherproject.pojos;


import org.bson.types.ObjectId;

import org.springframework.data.mongodb.repository.ReactiveMongoRepository;

import org.springframework.stereotype.Repository;

import reactor.core.publisher.Flux;

import reactor.core.publisher.Mono;


@Repository

public interface UserDataRepository extends ReactiveMongoRepository<UserData, ObjectId> {

  Mono<UserData> findByEmail(String name);

}

otherproject包含在 gradle中


compile project(':pojobase')

我已经添加了


@ComponentScan(basePackages = {"com.my.firstproject", "com.my.otherproject"})

到一个@Configuration文件。


当我尝试在我的主项目中使用上述存储库时,我收到一条错误消息


描述:


com.my.firstproject.controllers.CustomerController 中构造函数的参数 0 需要找不到类型为“com.my.otherproject.pojos.UserDataRepository”的 bean。


行动:


考虑在您的配置中定义“com.my.otherproject.pojos.UserDataRepository”类型的 bean。


是否可以在我的 spring 应用程序中使用实体和存储库?


幕布斯7119047
浏览 64回答 1
1回答

Cats萌萌

加课@EnableReactiveMongoRepositories(basePackages = {"com.my.otherproject.pojos"})_Main@EnableReactiveMongoRepositories(basePackages = {"com.my.otherproject.pojos"})public class Main {public static void main(String[] args) {&nbsp; &nbsp; SpringApplication.run(Main.class);&nbsp; &nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java