Guest User

Untitled

a guest
Dec 18th, 2017
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. spring.jpa.hibernate.ddl-auto=create-drop
  2. spring.datasource.url=jdbc:postgres://yhywdmylnzimrj:0c2f7...
  3. spring.datasource.username=yhywdmylnzimrj
  4. spring.datasource.password=0c2f7f8c...
  5.  
  6. <?xml version="1.0" encoding="UTF-8"?>
  7. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  8. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  9. <modelVersion>4.0.0</modelVersion>
  10.  
  11. <groupId>com.quicktutorialz.learnmicroservices</groupId>
  12. <artifactId>DemoHeroku</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <packaging>jar</packaging>
  15.  
  16. <name>DemoHeroku</name>
  17. <description>Demo project for Spring Boot</description>
  18.  
  19. <parent>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-parent</artifactId>
  22. <version>1.5.9.RELEASE</version>
  23. <relativePath/> <!-- lookup parent from repository -->
  24. </parent>
  25.  
  26. <properties>
  27. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  28. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  29. <java.version>1.8</java.version>
  30. </properties>
  31.  
  32. <dependencies>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-starter-data-jpa</artifactId>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-starter-web</artifactId>
  40. </dependency>
  41.  
  42. <dependency>
  43. <groupId>org.postgresql</groupId>
  44. <artifactId>postgresql</artifactId>
  45. <scope>runtime</scope>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.projectlombok</groupId>
  49. <artifactId>lombok</artifactId>
  50. <optional>true</optional>
  51. <version>1.16.10</version> <!-- added -->
  52. </dependency>
  53. <dependency>
  54. <groupId>org.springframework.boot</groupId>
  55. <artifactId>spring-boot-starter-test</artifactId>
  56. <scope>test</scope>
  57. </dependency>
  58. </dependencies>
  59.  
  60. <build>
  61. <plugins>
  62. <plugin>
  63. <groupId>org.springframework.boot</groupId>
  64. <artifactId>spring-boot-maven-plugin</artifactId>
  65. </plugin>
  66. </plugins>
  67. </build>
  68. </project>
  69.  
  70. package com.quicktutorialz.learnmicroservices.DemoHeroku;
  71.  
  72. import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.AuthorDao;
  73. import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.BookDao;
  74. import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author;
  75. import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book;
  76. import org.springframework.beans.factory.annotation.Autowired;
  77. import org.springframework.boot.SpringApplication;
  78. import org.springframework.boot.autoconfigure.SpringBootApplication;
  79. import org.springframework.web.bind.annotation.PathVariable;
  80. import org.springframework.web.bind.annotation.RequestMapping;
  81. import org.springframework.web.bind.annotation.RestController;
  82.  
  83. import javax.annotation.PostConstruct;
  84. import javax.validation.Valid;
  85. import java.util.List;
  86.  
  87. @RestController
  88. @SpringBootApplication
  89. public class DemoHerokuApplication {
  90.  
  91. public static void main(String[] args) {
  92. SpringApplication.run(DemoHerokuApplication.class, args);
  93. }
  94.  
  95. @Autowired AuthorDao authorDao;
  96. @Autowired BookDao bookDao;
  97.  
  98. @RequestMapping("/")
  99. public String hello(){
  100. return "Hello!";
  101. }
  102.  
  103. @RequestMapping("/books")
  104. public List<Book> getBooks(){
  105. return bookDao.findAll();
  106. }
  107.  
  108. @RequestMapping("/books/{id}")
  109. public Book getOneBook(@PathVariable(name = "id") Integer id){
  110. return bookDao.findOne(id);
  111. }
  112.  
  113. @RequestMapping("/authors")
  114. public List<Author> getAuthors(){
  115. return authorDao.findAll();
  116. }
  117.  
  118. @RequestMapping("/authors/{id}")
  119. public Author getOneAuthor(@PathVariable(name = "id") Integer id){
  120. return authorDao.findOne(id);
  121. }
  122.  
  123. @RequestMapping("/books/save")
  124. public Book saveBook(@Valid Book book){
  125. return bookDao.save(book);
  126. }
  127.  
  128. @RequestMapping("/books/delete/{id}")
  129. public List<Book> deleteBook(@PathVariable(name = "id") Integer id){
  130. bookDao.delete(id);
  131. return bookDao.findAll();
  132. }
  133.  
  134. @RequestMapping("/authors/save")
  135. public Author saveAuthor(@Valid Author author){
  136. return authorDao.save(author);
  137. }
  138.  
  139. @RequestMapping("/authors/delete/{id}")
  140. public List<Author> deleteAuthor(@PathVariable(name = "id") Integer id){
  141. authorDao.delete(id);
  142. return authorDao.findAll();
  143. }
  144.  
  145. @PostConstruct
  146. private void fillDatabase(){
  147. authorDao.save(new Author(null, "Gino Camarda", "gino@quicktutorialz.com"));
  148. authorDao.save(new Author(null, "Attilia Nomeldini", "attilia@quicktutorialz.com"));
  149.  
  150. bookDao.save(new Book(null, "Il basket per me", "Saggio sportivo", null, 1));
  151. bookDao.save(new Book(null, "W il basket", "Saggio sportivo", null, 1));
  152.  
  153. bookDao.save(new Book(null, "Giornali e pareri", "Saggio giornalistico", null, 2));
  154. bookDao.save(new Book(null, "Versioni della verita", "Saggio giornalistico", null, 2));
  155.  
  156. }
  157. }
  158.  
  159. package com.quicktutorialz.learnmicroservices.DemoHeroku.entities;
  160.  
  161. import lombok.AllArgsConstructor;
  162. import lombok.Getter;
  163. import lombok.NoArgsConstructor;
  164. import lombok.Setter;
  165. import org.hibernate.validator.constraints.NotBlank;
  166.  
  167. import javax.persistence.*;
  168.  
  169. @Entity @Table(name="authors") @AllArgsConstructor @NoArgsConstructor
  170. @Getter @Setter
  171. public class Author {
  172.  
  173. @Id @Column(name="ID") @GeneratedValue
  174. private Integer id;
  175. @Column(name="NAME") @NotBlank
  176. private String name;
  177. @Column(name="EMAIL") @NotBlank
  178. private String email;
  179. }
  180.  
  181. package com.quicktutorialz.learnmicroservices.DemoHeroku.entities;
  182.  
  183. import lombok.AllArgsConstructor;
  184. import lombok.Getter;
  185. import lombok.NoArgsConstructor;
  186. import lombok.Setter;
  187. import org.hibernate.validator.constraints.NotBlank;
  188.  
  189. import javax.persistence.*;
  190. import javax.validation.constraints.NotNull;
  191. import java.util.Date;
  192.  
  193. @Entity @Table(name="books")
  194. @AllArgsConstructor @NoArgsConstructor @Getter @Setter
  195. public class Book {
  196. @Id @Column(name="ID") @GeneratedValue
  197. private Integer id;
  198. @Column(name="TITLE") @NotBlank
  199. private String title;
  200. @Column(name="TITLE") @NotBlank
  201. private String description;
  202. @Column(name="TITLE")
  203. private Date dateOfRelease;
  204. @Column(name="TITLE") @NotNull
  205. private int authorId;
  206.  
  207. @PrePersist
  208. private void setDate(){
  209. this.dateOfRelease = new Date();
  210. }
  211. }
  212.  
  213. package com.quicktutorialz.learnmicroservices.DemoHeroku.daos;
  214.  
  215. import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author;
  216. import org.springframework.data.jpa.repository.JpaRepository;
  217.  
  218. public interface AuthorDao extends JpaRepository<Author, Integer>{
  219.  
  220. }
  221.  
  222. package com.quicktutorialz.learnmicroservices.DemoHeroku.daos;
  223.  
  224. import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book;
  225. import org.springframework.data.jpa.repository.JpaRepository;
  226.  
  227. public interface BookDao extends JpaRepository<Book, Integer>{
  228. }
  229.  
  230. Description:
  231.  
  232. Cannot determine embedded database driver class for database type NONE
  233.  
  234. at=error code=H10 desc="App crashed" method=GET path="/"
Add Comment
Please, Sign In to add comment