Desacoplando Aカンガルーデドムは、ニオデUa Aplicaを得ます


フェラチオナス
  • Java SDK
  • Docker
  • Postman
  • IDEデスー

  • vamosアゴラfazer o da nossa aplicaは、o oをnooしていますda dsosのpostgres paraダイナモをします.XML que devera ficar assimpom.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.6</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>ddd</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>ddd</name>
        <description>Demo project for Spring Boot</description>
        <properties>
            <java.version>11</java.version>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.amazonaws</groupId>
                    <artifactId>aws-java-sdk-bom</artifactId>
                    <version>1.11.614</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-validation</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.github.derjust</groupId>
                <artifactId>spring-data-dynamodb</artifactId>
                <version>5.1.0</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    
    Vamos変則的なタム・ム・ノズソapplication.properties パラデキシナーapenas o終点デacesso ao nosso bancoデdadosダイナモapplication.properties
    server.error.include-message=always
    aws.amazonDynamoDBEndpoint=http://localhost:8000
    
    Roo o seguinte comando em seuターミナルcmd para criar um banco de dados AWS/Dynamodb dentro de umコンテナDockerdocker run -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -inMemory -sharedDbVamos Agora fazer a a transi poo o o do armazenamento da nossa aplica des de de de de gggse se pregres paraダイナモUsuarioAbstractRepositoryDB ,タブラエラダイナソーUsuario E CriarオーマClasseデConfiguraは、AceesoオアシスAnd AWS/DynamoDbです.
    パッケージパッケージinfrastructure クリエアムパキージconfig e dentro deleパッケージdynamodb , Dentro DoパッケージDynamodbは、CLASSE DE Configilerを支持しますDynamoDbConfig .DynamoDbConfig
    import com.amazonaws.client.builder.AwsClientBuilder;
    import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
    import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig;
    import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
    import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
    import com.amazonaws.services.dynamodbv2.util.TableUtils;
    import com.example.ddd.core.usuario.Usuario;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class DynamoDbConfig {
    
        @Value(("${aws.amazonDynamoDBEndpoint}"))
        private String amazonDynamoDBEndpoint;
    
        @Bean
        public DynamoDBMapper dynamoDBMapper() {
            AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
                    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(amazonDynamoDBEndpoint, "us-west-2"))
                    .build();
            DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder()
                    .withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.CLOBBER)
                    .withConsistentReads(DynamoDBMapperConfig.ConsistentReads.CONSISTENT)
                    .withTableNameOverride(null)
                    .withPaginationLoadingStrategy(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING)
                    .build();
            DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(client, mapperConfig);
            init(dynamoDBMapper, client);
            return dynamoDBMapper;
        }
    
    
        public void init(DynamoDBMapper dynamoDBMapper, AmazonDynamoDB client) {
    
            CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(Usuario.class);
            tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
    
            if (TableUtils.createTableIfNotExists(client, tableRequest)) {
                System.out.println("Table created");
            }
    
        }
    
    }
    
    クラスを変更するUsuarioAbstractRepositoryDB アペッサーOダイナモE Armazenar Ou Retornar Os Dados que PremiisosUsuarioAbstractRepositoryDB
    import java.util.List;
    
    @Repository
    public class UsuarioAbstractRepositoryDB {
    
        private DynamoDBMapper dynamoDBMapper;
    
    
        @Autowired
        public UsuarioAbstractRepositoryDB(DynamoDBMapper dynamoDBMapper) {
            this.dynamoDBMapper = dynamoDBMapper;
        }
    
        public Usuario buscaUsuarioPorId(String usuarioId) {
            return dynamoDBMapper.load(Usuario.class, usuarioId);
        }
    
       public List<Usuario> buscaUsuarios() {
    
           final DynamoDBScanExpression paginatedScanListExpression = new DynamoDBScanExpression();
           final PaginatedScanList<Usuario> usuarioList = dynamoDBMapper.scan(Usuario.class, paginatedScanListExpression);
           return usuarioList;
       }
    
        public String deletaUsuario(String usuarioId){
            Usuario usuario = dynamoDBMapper.load(Usuario.class,usuarioId);
            dynamoDBMapper.delete(usuario);
            return "Usuario deletado com sucesso";
        }
    
        public Usuario criaUsuario(Usuario usuario) {
            dynamoDBMapper.save(usuario);
            return usuario;
        }
    
        public Usuario updateUsuario(String usuarioId, Usuario usuario) {
    
            dynamoDBMapper.save(usuario,
                    new DynamoDBSaveExpression()
                            .withExpectedEntry("usuarioId",
                                    new ExpectedAttributeValue(
                                            new AttributeValue().withS(usuarioId)
                                    )));
            Usuario usuarioAtualizado = buscaUsuarioPorId(usuarioId);
            return usuarioAtualizado;
        }
    }
    
    アゴラがそうである前に、Criaは、Aを得ますUsuario アルゼンチン.Usuario
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
    import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
    
    @DynamoDBTable(tableName = "usuario")
    public class Usuario {
    
        @DynamoDBHashKey(attributeName = "usuarioId")
        @DynamoDBAutoGeneratedKey
        private String userId;
    
        @DynamoDBAttribute(attributeName = "name")
        private String name;
    
        @DynamoDBAttribute(attributeName = "email")
        private String email;
    
        @DynamoDBAttribute(attributeName = "cpf")
        private String cpf;
    
        @Deprecated
        public Usuario() {
        }
    
        public Usuario(String name, String email, String cpf) {
            this.name = name;
            this.email = email;
            this.cpf = cpf;
        }
    
        public String getUserId() {
            return userId;
        }
    
        public void setUserId(String userId) {
            this.userId = userId;
        }
    
        public String getName() {
            return name;
        }
    
        public String getEmail() {
            return email;
        }
    
        public String getCpf() {
            return cpf;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    
        public void setCpf(String cpf) {
            this.cpf = cpf;
        }
    
    }
    
    E . Pronon , Reissi Ada Resiizada SEM Preisar Mexer na Camada de DOM Land ' nio ou na camada de acesso externo de nossa aplicaの結果Postman .
    臼尾理道

    リラユサリオ

    ウサリオアルマゼンドダイナモ

    E ISSO AIギャララ、エサウルティマパティdeixareiなしメウgithub パラクェイククエザーアセッセル
    Deixo Aqui Tamb m m meu para quem quiser me adicionar、グラタンa todos que leram este artigo e bora aprender galera .