Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spring.jpa.hibernate.ddl-auto=create-drop
- spring.datasource.url=jdbc:postgres://yhywdmylnzimrj:0c2f7...
- spring.datasource.username=yhywdmylnzimrj
- spring.datasource.password=0c2f7f8c...
- <?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>
- <groupId>com.quicktutorialz.learnmicroservices</groupId>
- <artifactId>DemoHeroku</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>DemoHeroku</name>
- <description>Demo project for Spring Boot</description>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.9.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <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>
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- <version>1.16.10</version> <!-- added -->
- </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>
- </project>
- package com.quicktutorialz.learnmicroservices.DemoHeroku;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.AuthorDao;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.BookDao;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.PostConstruct;
- import javax.validation.Valid;
- import java.util.List;
- @RestController
- @SpringBootApplication
- public class DemoHerokuApplication {
- public static void main(String[] args) {
- SpringApplication.run(DemoHerokuApplication.class, args);
- }
- @Autowired AuthorDao authorDao;
- @Autowired BookDao bookDao;
- @RequestMapping("/")
- public String hello(){
- return "Hello!";
- }
- @RequestMapping("/books")
- public List<Book> getBooks(){
- return bookDao.findAll();
- }
- @RequestMapping("/books/{id}")
- public Book getOneBook(@PathVariable(name = "id") Integer id){
- return bookDao.findOne(id);
- }
- @RequestMapping("/authors")
- public List<Author> getAuthors(){
- return authorDao.findAll();
- }
- @RequestMapping("/authors/{id}")
- public Author getOneAuthor(@PathVariable(name = "id") Integer id){
- return authorDao.findOne(id);
- }
- @RequestMapping("/books/save")
- public Book saveBook(@Valid Book book){
- return bookDao.save(book);
- }
- @RequestMapping("/books/delete/{id}")
- public List<Book> deleteBook(@PathVariable(name = "id") Integer id){
- bookDao.delete(id);
- return bookDao.findAll();
- }
- @RequestMapping("/authors/save")
- public Author saveAuthor(@Valid Author author){
- return authorDao.save(author);
- }
- @RequestMapping("/authors/delete/{id}")
- public List<Author> deleteAuthor(@PathVariable(name = "id") Integer id){
- authorDao.delete(id);
- return authorDao.findAll();
- }
- @PostConstruct
- private void fillDatabase(){
- authorDao.save(new Author(null, "Gino Camarda", "gino@quicktutorialz.com"));
- authorDao.save(new Author(null, "Attilia Nomeldini", "attilia@quicktutorialz.com"));
- bookDao.save(new Book(null, "Il basket per me", "Saggio sportivo", null, 1));
- bookDao.save(new Book(null, "W il basket", "Saggio sportivo", null, 1));
- bookDao.save(new Book(null, "Giornali e pareri", "Saggio giornalistico", null, 2));
- bookDao.save(new Book(null, "Versioni della verita", "Saggio giornalistico", null, 2));
- }
- }
- package com.quicktutorialz.learnmicroservices.DemoHeroku.entities;
- import lombok.AllArgsConstructor;
- import lombok.Getter;
- import lombok.NoArgsConstructor;
- import lombok.Setter;
- import org.hibernate.validator.constraints.NotBlank;
- import javax.persistence.*;
- @Entity @Table(name="authors") @AllArgsConstructor @NoArgsConstructor
- @Getter @Setter
- public class Author {
- @Id @Column(name="ID") @GeneratedValue
- private Integer id;
- @Column(name="NAME") @NotBlank
- private String name;
- @Column(name="EMAIL") @NotBlank
- private String email;
- }
- package com.quicktutorialz.learnmicroservices.DemoHeroku.entities;
- import lombok.AllArgsConstructor;
- import lombok.Getter;
- import lombok.NoArgsConstructor;
- import lombok.Setter;
- import org.hibernate.validator.constraints.NotBlank;
- import javax.persistence.*;
- import javax.validation.constraints.NotNull;
- import java.util.Date;
- @Entity @Table(name="books")
- @AllArgsConstructor @NoArgsConstructor @Getter @Setter
- public class Book {
- @Id @Column(name="ID") @GeneratedValue
- private Integer id;
- @Column(name="TITLE") @NotBlank
- private String title;
- @Column(name="TITLE") @NotBlank
- private String description;
- @Column(name="TITLE")
- private Date dateOfRelease;
- @Column(name="TITLE") @NotNull
- private int authorId;
- @PrePersist
- private void setDate(){
- this.dateOfRelease = new Date();
- }
- }
- package com.quicktutorialz.learnmicroservices.DemoHeroku.daos;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author;
- import org.springframework.data.jpa.repository.JpaRepository;
- public interface AuthorDao extends JpaRepository<Author, Integer>{
- }
- package com.quicktutorialz.learnmicroservices.DemoHeroku.daos;
- import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book;
- import org.springframework.data.jpa.repository.JpaRepository;
- public interface BookDao extends JpaRepository<Book, Integer>{
- }
- Description:
- Cannot determine embedded database driver class for database type NONE
- at=error code=H10 desc="App crashed" method=GET path="/"
Add Comment
Please, Sign In to add comment