I have multiple projects using spring 2.1.3 and would like to let them share some entities, together with their repositories.
Sample repository:
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);
}
The otherproject
is included with gradle
compile project(':pojobase')
And I have added
@ComponentScan(basePackages = {"com.my.firstproject", "com.my.otherproject"})
to a @Configuration
file.
When I try to use above Repository in my main project, I get an error saying
Description:
Parameter 0 of constructor in com.my.firstproject.controllers.CustomerController required a bean of type 'com.my.otherproject.pojos.UserDataRepository' that could not be found.
Action:
Consider defining a bean of type 'com.my.otherproject.pojos.UserDataRepository' in your configuration.
Is it somehow possible to use the entities and repositories in my spring app?
Add @EnableReactiveMongoRepositories(basePackages = {"com.my.otherproject.pojos"})
on Main
class
@EnableReactiveMongoRepositories(basePackages = {"com.my.otherproject.pojos"})
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class);
}
}