【发布时间】:2020-04-06 01:12:35
【问题描述】:
这是我得到的错误:
Description:
Field andiRepository in com.service.datafetcher.AllAndisDataFetcher required a bean of type 'com.repositories.AndiRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.repositories.AndiRepository' in your configuration.
这是需要 bean 的数据获取器文件:
import com.models.Andi;
import com.repositories.AndiRepository;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class AllAndisDataFetcher implements DataFetcher<List<Andi>> {
@Autowired
AndiRepository andiRepository;
@Override
public List<Andi> get(DataFetchingEnvironment dataFetchingEnvironment) throws Exception {
return andiRepository.findAll();
}
}
这是驻留在“com”中的主要方法。
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@ComponentScan("com.repositories")//to scan repository files
@EntityScan("com.models")
@EnableJpaRepositories("com.repositories.AndiRepository")
public class DynamoDBApplication {
public static void main(String[] args) {
SpringApplication.run(DynamoDBApplication.class, args);
}
}
模型、存储库、服务、包都在主 com 包中。
这是存储库文件:
package com.repositories;
import com.andiskillsmaxmodels.Andi;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AndiRepository extends CrudRepository<Andi, Integer> {
}
谢谢
【问题讨论】:
-
能否指定
main()方法所在类的完整包名? -
我会把它添加到问题中,谢谢
-
我已经添加了。
-
这是一个 maven 多模块项目吗?
-
我不确定这意味着什么,但这应该是一个简单的端点,它在正文中接收一个 graphql 查询,然后在 dynamodb 上执行它。
标签: java spring spring-boot graphql amazon-dynamodb