'How to find a Bean instance of MongoRepository?

I am trying to use a MongoRepository, but Spring complains, that no instance of the MonoRepository-Interface is in the context.

@SpringBootApplication
public class BackendApplication {
    public static void main(String[] args) {
        SpringApplication.run(BackendApplication.class, args);
    }
}

@Document(collection = "tableItems")
class TableItem {

    @Id
    public String id;
    public int roundNbr;
}

interface TableItemsRepository extends MongoRepository<TableItem, String> {
}

@Service
class TableItemsService {

    @Autowired
    public TableItemsService(TableItemsRepository tableItemsRepository) {
    }
}

The server complains:

Parameter 0 of constructor in backend.TableItemsService required a bean of type 'backend.TableItemsRepository' that could not be found.


Action:

Consider defining a bean of type 'backend.TableItemsRepository' in your configuration.

my maven pom.xml:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>3.4.0</version>
</dependency>

How can I get a bean instance of my MongoRepository?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source