reformatted as per standard formatter and incorporated review comments.

This commit is contained in:
ajay74984 2020-02-15 09:32:50 +01:00
parent 7feb7bf9d8
commit d868eda952
12 changed files with 143 additions and 161 deletions

View File

@ -1,70 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-hexagonal</artifactId> <artifactId>spring-boot-hexagonal</artifactId>
<name>spring-boot-hexagonal</name> <name>spring-boot-hexagonal</name>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath> <relativePath>../../parent-boot-2</relativePath>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>spring-boot-hexagonal</finalName> <finalName>spring-boot-hexagonal</finalName>
<resources> <resources>
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <configuration>
<classifier>exec</classifier> <classifier>exec</classifier>
</configuration> </configuration>
</plugin> </plugin>
<plugin> </plugins>
<groupId>org.apache.maven.plugins</groupId> </build>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
</project> </project>

View File

@ -5,9 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
} }

View File

@ -3,23 +3,23 @@ package com.baeldung.adapter;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.baeldung.domain.Document; import com.baeldung.domain.Document;
import com.baeldung.port.DocumentRepo; import com.baeldung.domain.port.DocumentRepo;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Repository @Repository
public class DocumentRepositoryImpl implements DocumentRepo { public class DocumentRepositoryImpl implements DocumentRepo {
private Map<String, Document> documentMap = new HashMap<>(); private Map<String, Document> documentMap = new HashMap<>();
@Override @Override
public void storeDocument(Document document) { public void storeDocument(Document document) {
documentMap.put(document.getId(), document); documentMap.put(document.getId(), document);
} }
@Override @Override
public Document findDocumentById(String id) { public Document findDocumentById(String id) {
return documentMap.get(id); return documentMap.get(id);
} }
} }

View File

@ -1,26 +1,25 @@
package com.baeldung.adapter; package com.baeldung.adapter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.baeldung.domain.Document; import com.baeldung.domain.Document;
import com.baeldung.port.DocumentService; import com.baeldung.domain.port.DocumentService;
@RestController @RestController
@RequestMapping("/doc") @RequestMapping("/doc")
public class DocumentRestAdapter { public class DocumentRestAdapter {
@Autowired @Autowired
private DocumentService documentService; private DocumentService documentService;
@PostMapping @PostMapping
public void createDocument(@RequestBody Document document) { public void createDocument(@RequestBody Document document) {
documentService.createDocument(document); documentService.createDocument(document);
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public Document findById(@PathVariable String id) { public Document findById(@PathVariable String id) {
return documentService.findById(id); return documentService.findById(id);
} }
} }

View File

@ -1,21 +1,23 @@
package com.baeldung.domain; package com.baeldung.domain;
public class Document { public class Document {
private String id; private String id;
private String data; private String data;
public String getId() { public String getId() {
return id; return id;
} }
public void setId(String id) {
this.id = id; public void setId(String id) {
} this.id = id;
public String getData() { }
return data;
} public String getData() {
public void setData(String data) { return data;
this.data = data; }
}
public void setData(String data) {
this.data = data;
}
} }

View File

@ -0,0 +1,9 @@
package com.baeldung.domain.port;
import com.baeldung.domain.Document;
public interface DocumentRepo {
void storeDocument(Document document);
Document findDocumentById(String id);
}

View File

@ -0,0 +1,11 @@
package com.baeldung.domain.port;
import com.baeldung.domain.Document;
public interface DocumentService {
void createDocument(Document document);
Document findById(String id);
}

View File

@ -0,0 +1,25 @@
package com.baeldung.domain.port.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.domain.Document;
import com.baeldung.domain.port.DocumentRepo;
import com.baeldung.domain.port.DocumentService;
@Service
public class DocumentServiceImpl implements DocumentService {
@Autowired
private DocumentRepo documentRepo;
@Override
public void createDocument(Document document) {
documentRepo.storeDocument(document);
}
@Override
public Document findById(String id) {
return documentRepo.findDocumentById(id);
}
}

View File

@ -1,10 +0,0 @@
package com.baeldung.port;
import com.baeldung.domain.Document;
public interface DocumentRepo {
void storeDocument(Document document);
Document findDocumentById(String id);
}

View File

@ -1,11 +0,0 @@
package com.baeldung.port;
import com.baeldung.domain.Document;
public interface DocumentService {
void createDocument(Document document);
Document findById(String id);
}

View File

@ -1,25 +0,0 @@
package com.baeldung.port.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.domain.Document;
import com.baeldung.port.DocumentRepo;
import com.baeldung.port.DocumentService;
@Service
public class DocumentServiceImpl implements DocumentService {
@Autowired
private DocumentRepo documentRepo;
@Override
public void createDocument(Document document) {
documentRepo.storeDocument(document);
}
@Override
public Document findById(String id) {
return documentRepo.findDocumentById(id);
}
}

View File

@ -8,9 +8,9 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest @SpringBootTest
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
class ApplicationUnitTest { class ApplicationUnitTest {
@Test @Test
public void contextLoads() { public void contextLoads() {
} }
} }