将DynamoDB服务注入Spring控制器

问题描述

我有一个带有以下代码的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.

我已经检查过,文件夹结构看起来是否正确:

Folder Structure

我试图在可以正常工作的存储库中创建一些单元测试,因此我有点怀疑在使用@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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...