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:
mvn clean install
mvn spring-boot:run
Swagger endpoints:
http://localhost:8080/v2/api-docs
http://localhost:8080/swagger-ui.html

View File

@ -1,60 +1,42 @@
<?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 http://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.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-configuration</name>
<description>Demo project for Spring Boot Configuration </description>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-configuration</name>
<description>Demo project for Spring Boot Configuration</description>
<properties>
<java.version>1.8</java.version>
</properties>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- 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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

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

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;
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<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));
}
public interface PersonService {
}

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`)
);

View File

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