我想用 Spring 数据 mongodb 实现自定义 repo。应用程序.java:
@SpringBootApplication
public class Application implements CommandLineRunner{
@Autowired
private CustomerRepositoryCustom repo;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println(this.repo.customMethod());
}
}
我的自定义存储库 CustomerRepositoryCustom.java
public interface CustomerRepositoryCustom {
List<Customer> customMethod();
}
自定义实现CustomCustomerRepositoryImpl.java
public class CustomCustomerRepositoryImpl implements CustomerRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public List<Customer> customMethod() {
return this.mongoTemplate.findAll(Customer.class);
}
}
代码结构
-Application.java
dal
model...
repository
-CustomCustomerRepositoryImpl.java
-CustomerRepositoryCustom.java
当我尝试构建它时,我收到一个错误:
**Description**:
Field repo in socketApp.Application required a bean of type 'socketApp.dal.repository.CustomerRepositoryCustom' that could not be found.
**Action**:
Consider defining a bean of type 'socketApp.dal.repository.CustomerRepositoryCustom' in your configuration.