问题描述
我有一个带有以下代码的Spring Controller:
@RestController
public class CustomerController {
@Autowired
DynamoDBRepository dynamoDBRepository;
@RequestMapping("/")
public String getUser(){
return "Hello from " + CustomerController.class.toString();
}
@RequestMapping("/customer")
public Customer getRandomUser(){
return new Customer(
"Kristoffer",24,"kristofferlocktolboll@gamil.com","password123",100000000
);
}
@PostMapping(value = "/customer")
public String insertCustomer(@RequestBody Customer customer){
System.out.println(customer);
String jsonDocument = dynamoDBRepository.insertCustomer(customer);
return jsonDocument;
}
}
运行应用程序时出现以下错误:
Action:
Consider defining a bean of type 'com.example.repositories.DynamoDBRepository' in your configuration.
我试图在可以正常工作的存储库中创建一些单元测试,因此我有点怀疑在使用@Autowired
注释方面我做错了什么。
这是我的存储库示例代码:
public class DynamoDBRepository {
private AmazonDynamoDB dbInstance;
public DynamoDBRepository() {
this.dbInstance = DynamoDBProvider.createInstance();
}
public String insertCustomer(Customer customer){
DynamoDB dynamoDB = new DynamoDB(this.dbInstance);
Table table = dynamoDB.getTable("BankCustomer");
Item item = new Item()
.withPrimaryKey("id",customer.getId())
.withString("name",customer.getName())
.withString("password",customer.getPassword());
table.putItem(item);
System.out.println("Inserted item " + item.toJSON());
return item.toJSON();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)