BAEL-2728

- Removed unnecessary code
This commit is contained in:
vatsalgosar 2019-07-24 00:18:45 +05:30
parent f43db12fcb
commit eaa0c63620
12 changed files with 56 additions and 206 deletions

View File

@ -4,7 +4,3 @@ SprintBootConfiguration annotation
commands: commands:
mvn clean install mvn clean install
mvn spring-boot:run mvn spring-boot:run
Swagger endpoints:
http://localhost:8080/v2/api-docs
http://localhost:8080/swagger-ui.html

View File

@ -12,7 +12,7 @@
<artifactId>spring-boot-configuration</artifactId> <artifactId>spring-boot-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>spring-boot-configuration</name> <name>spring-boot-configuration</name>
<description>Demo project for Spring Boot Configuration </description> <description>Demo project for Spring Boot Configuration</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
@ -23,24 +23,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- h2 database dependency-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- hibernate dependency-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</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>

View File

@ -1,15 +1,14 @@
package com.baeldung; package com.baeldung;
import com.baeldung.service.PersonService;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
@EnableAutoConfiguration import com.baeldung.ServiceImpl.PersonServiceImpl;
@ComponentScan(basePackages = {"com.baeldung.*"}) import com.baeldung.service.PersonService;
@ComponentScan(basePackages = { "com.baeldung.*" })
@SpringBootConfiguration @SpringBootConfiguration
public class Application { public class Application {
@ -19,7 +18,6 @@ public class Application {
@Bean @Bean
public PersonService personService() { public PersonService personService() {
return new PersonService(); return new PersonServiceImpl();
} }
} }

View File

@ -0,0 +1,6 @@
package com.baeldung.ServiceImpl;
import com.baeldung.service.PersonService;
public class PersonServiceImpl implements PersonService {
}

View File

@ -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<Person> 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);
}
}

View File

@ -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;
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.exception;
public class PersonNotFoundException extends Exception {
public PersonNotFoundException(String message) {
super(message);
}
}

View File

@ -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<Person, Long> {
}

View File

@ -1,34 +1,4 @@
package com.baeldung.service; package com.baeldung.service;
import com.baeldung.domain.Person; public interface PersonService {
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<Person> getPersons() {
return (List<Person>) personRepository.findAll();
}
public Person getPersonById(long id) throws PersonNotFoundException {
Optional<Person> optionalDog = personRepository.findById(id);
return optionalDog.orElseThrow(() -> new PersonNotFoundException("Couldn't find a Person with id: " + id));
}
} }

View File

@ -1,3 +0,0 @@
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2

View File

@ -1,5 +0,0 @@
CREATE TABLE `person` (
`id` INT(11) NOT NULL,
`name` VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);