|
| 1 | + |
| 2 | + |
| 3 | +## what is your application? |
| 4 | +Java application can be compiled down to one executable file (ex: .jar, .war). In our case, we will be creating a jar file that will be saved to a directory called __target__. |
| 5 | +This can be done from your IDE (ex: Intellij, Eclipse). |
| 6 | +```bash |
| 7 | +$ mvn clean install |
| 8 | +$ ls target |
| 9 | +< there should be a bunch of files> |
| 10 | +classes |
| 11 | +generated-sources |
| 12 | +generated-test-sources |
| 13 | +maven-archiver |
| 14 | +maven-status |
| 15 | +postgres-demo-0.0.1-SNAPSHOT.jar |
| 16 | +postgres-demo-0.0.1-SNAPSHOT.jar.original |
| 17 | +surefire-reports |
| 18 | +test-classes |
| 19 | +``` |
| 20 | +to run you application from the command line |
| 21 | +```bash |
| 22 | +$ java -jar target/postgres-demo-0.0.1-SNAPSHOT.jar |
| 23 | +``` |
| 24 | +## what does your application need to run? |
| 25 | + |
| 26 | +- java 8 |
| 27 | + - maven |
| 28 | +- database (ex: postgres) |
| 29 | + - database table |
| 30 | + - databese username |
| 31 | + |
| 32 | +You can check this information in the application. |
| 33 | + |
| 34 | +To find the java version, check the pom.xml |
| 35 | +```bash |
| 36 | +$ cat pom.xml |
| 37 | +< lots of stuff will be in here> |
| 38 | +... |
| 39 | + <name>postgres-demo</name> |
| 40 | + <description>Demo project for Spring Boot</description> |
| 41 | + |
| 42 | + <parent> |
| 43 | + <groupId>org.springframework.boot</groupId> |
| 44 | + <artifactId>spring-boot-starter-parent</artifactId> |
| 45 | + <version>2.0.1.RELEASE</version> |
| 46 | + <relativePath/> <!-- lookup parent from repository --> |
| 47 | + </parent> |
| 48 | + |
| 49 | + <properties> |
| 50 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 51 | + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| 52 | + <java.version>1.8</java.version> |
| 53 | + </properties> |
| 54 | +... |
| 55 | +``` |
| 56 | + |
| 57 | +```bash |
| 58 | +$ cat src/main/resources/application.properties |
| 59 | +## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) |
| 60 | +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres_demo |
| 61 | +spring.datasource.username= |
| 62 | +spring.datasource.password= |
| 63 | + |
| 64 | +# The SQL dialect makes Hibernate generate better SQL for the chosen database |
| 65 | +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect |
| 66 | + |
| 67 | +# Hibernate ddl auto (create, create-drop, validate, update) |
| 68 | +spring.jpa.hibernate.ddl-auto = update |
| 69 | +``` |
| 70 | + |
| 71 | +In this example, our application uses a postgres database called _postgres_demo_. There is no username or password defined. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +--------- |
1 | 77 | ## Spring Boot, PostgreSQL, JPA, Hibernate REST API Demo
|
2 | 78 |
|
3 | 79 | ## Tutorial
|
@@ -31,4 +107,4 @@ Alternatively, you can package the application in the form of a JAR file and the
|
31 | 107 | ```bash
|
32 | 108 | mvn clean package
|
33 | 109 | java -jar target/postgres-demo-0.0.1-SNAPSHOT.jar
|
34 |
| -``` |
| 110 | +``` |
0 commit comments