From eaa0c63620d0ac7807a6ea65d95defcd8202d879 Mon Sep 17 00:00:00 2001 From: vatsalgosar Date: Wed, 24 Jul 2019 00:18:45 +0530 Subject: [PATCH] BAEL-2728 - Removed unnecessary code --- .../spring-boot-configuration/README.md | 4 - .../spring-boot-configuration/pom.xml | 88 ++++++++----------- .../main/java/com/baeldung/Application.java | 24 +++-- .../ServiceImpl/PersonServiceImpl.java | 6 ++ .../baeldung/controller/PersonController.java | 39 -------- .../main/java/com/baeldung/domain/Person.java | 38 -------- .../exception/PersonNotFoundException.java | 8 -- .../baeldung/repository/PersonRepository.java | 9 -- .../com/baeldung/service/PersonService.java | 32 +------ .../src/main/resources/application.properties | 3 - .../src/main/resources/schema.sql | 5 -- .../java/com/baeldung/ApplicationTests.java | 6 +- 12 files changed, 56 insertions(+), 206 deletions(-) create mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/ServiceImpl/PersonServiceImpl.java delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/controller/PersonController.java delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/domain/Person.java delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/exception/PersonNotFoundException.java delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/repository/PersonRepository.java delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/resources/application.properties delete mode 100644 spring-boot-bootstrap/spring-boot-configuration/src/main/resources/schema.sql diff --git a/spring-boot-bootstrap/spring-boot-configuration/README.md b/spring-boot-bootstrap/spring-boot-configuration/README.md index 35472d575a..d5ec5f63da 100644 --- a/spring-boot-bootstrap/spring-boot-configuration/README.md +++ b/spring-boot-bootstrap/spring-boot-configuration/README.md @@ -4,7 +4,3 @@ SprintBootConfiguration annotation commands: mvn clean install mvn spring-boot:run - -Swagger endpoints: -http://localhost:8080/v2/api-docs -http://localhost:8080/swagger-ui.html \ No newline at end of file diff --git a/spring-boot-bootstrap/spring-boot-configuration/pom.xml b/spring-boot-bootstrap/spring-boot-configuration/pom.xml index 02b2e53159..d7b4122c20 100644 --- a/spring-boot-bootstrap/spring-boot-configuration/pom.xml +++ b/spring-boot-bootstrap/spring-boot-configuration/pom.xml @@ -1,60 +1,42 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.6.RELEASE - - - com.baeldung - spring-boot-configuration - 0.0.1-SNAPSHOT - spring-boot-configuration - Demo project for Spring Boot Configuration + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.6.RELEASE + + + com.baeldung + spring-boot-configuration + 0.0.1-SNAPSHOT + spring-boot-configuration + Demo project for Spring Boot Configuration - - 1.8 - + + 1.8 + - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-test + test + + - - - com.h2database - h2 - runtime - - - - - org.hibernate - hibernate-entitymanager - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/Application.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/Application.java index 7021ae62fa..15adb4bb3e 100644 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/Application.java +++ b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/Application.java @@ -1,25 +1,23 @@ package com.baeldung; -import com.baeldung.service.PersonService; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Import; -@EnableAutoConfiguration -@ComponentScan(basePackages = {"com.baeldung.*"}) +import com.baeldung.ServiceImpl.PersonServiceImpl; +import com.baeldung.service.PersonService; + +@ComponentScan(basePackages = { "com.baeldung.*" }) @SpringBootConfiguration public class Application { - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } - @Bean - public PersonService personService() { - return new PersonService(); - } + @Bean + public PersonService personService() { + return new PersonServiceImpl(); + } } - diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/ServiceImpl/PersonServiceImpl.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/ServiceImpl/PersonServiceImpl.java new file mode 100644 index 0000000000..f08fbaa7f2 --- /dev/null +++ b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/ServiceImpl/PersonServiceImpl.java @@ -0,0 +1,6 @@ +package com.baeldung.ServiceImpl; + +import com.baeldung.service.PersonService; + +public class PersonServiceImpl implements PersonService { +} diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/controller/PersonController.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/controller/PersonController.java deleted file mode 100644 index 10d7386132..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/controller/PersonController.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.controller; - -import com.baeldung.domain.Person; -import com.baeldung.exception.PersonNotFoundException; -import com.baeldung.service.PersonService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/persons") -public class PersonController { - - @Autowired - PersonService personService; - - @GetMapping - public List getPersons() { - return personService.getPersons(); - } - - @PostMapping - public void addPerson(@RequestBody Person person) { - personService.add(person); - } - - @GetMapping("/{id}") - public Person getPersonById(@PathVariable(required = true) long id) throws PersonNotFoundException { - return personService.getPersonById(id); - } - - @DeleteMapping("/{id}") - public void removePerson(@PathVariable(required = true) long id) { - personService.delete(id); - } - - -} diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/domain/Person.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/domain/Person.java deleted file mode 100644 index e63836420c..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/domain/Person.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.domain; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Person { - - @Id - @GeneratedValue - private long id; - private String name; - - public Person() {} - - public Person(long id, String name) { - this.id = id; - this.name = name; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} - diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/exception/PersonNotFoundException.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/exception/PersonNotFoundException.java deleted file mode 100644 index 048197a072..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/exception/PersonNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.exception; - -public class PersonNotFoundException extends Exception { - - public PersonNotFoundException(String message) { - super(message); - } -} diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/repository/PersonRepository.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/repository/PersonRepository.java deleted file mode 100644 index b542b5ea0b..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/repository/PersonRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.domain.Person; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PersonRepository extends CrudRepository { -} diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/service/PersonService.java b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/service/PersonService.java index 74f7cb0a70..e959e3b835 100644 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/service/PersonService.java +++ b/spring-boot-bootstrap/spring-boot-configuration/src/main/java/com/baeldung/service/PersonService.java @@ -1,34 +1,4 @@ package com.baeldung.service; -import com.baeldung.domain.Person; -import com.baeldung.exception.PersonNotFoundException; -import com.baeldung.repository.PersonRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; - -//@Service -public class PersonService { - - @Autowired - PersonRepository personRepository; - - public void add(Person person) { - personRepository.save(person); - } - - public void delete(long id) { - personRepository.deleteById(id); - } - - public List getPersons() { - return (List) personRepository.findAll(); - } - - public Person getPersonById(long id) throws PersonNotFoundException { - Optional optionalDog = personRepository.findById(id); - return optionalDog.orElseThrow(() -> new PersonNotFoundException("Couldn't find a Person with id: " + id)); - } +public interface PersonService { } diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/application.properties b/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/application.properties deleted file mode 100644 index 7de28fe306..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -# H2 -spring.h2.console.enabled=true -spring.h2.console.path=/h2 diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/schema.sql b/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/schema.sql deleted file mode 100644 index 02a7aca232..0000000000 --- a/spring-boot-bootstrap/spring-boot-configuration/src/main/resources/schema.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE `person` ( - `id` INT(11) NOT NULL, - `name` VARCHAR(50) NULL DEFAULT NULL, - PRIMARY KEY (`id`) -); \ No newline at end of file diff --git a/spring-boot-bootstrap/spring-boot-configuration/src/test/java/com/baeldung/ApplicationTests.java b/spring-boot-bootstrap/spring-boot-configuration/src/test/java/com/baeldung/ApplicationTests.java index f239fc76cc..3bd3cc2ec6 100644 --- a/spring-boot-bootstrap/spring-boot-configuration/src/test/java/com/baeldung/ApplicationTests.java +++ b/spring-boot-bootstrap/spring-boot-configuration/src/test/java/com/baeldung/ApplicationTests.java @@ -9,8 +9,8 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest public class ApplicationTests { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } }