java - Connect to PostgreSQL from SpringBootApplication -
i building simple spring application scratch using maven , postgresql.
i've been following thousand of tutorials isn't clear me store different configurations connect , work postgresql database.
my pom.xml
file:
<?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>org.springframework</groupid> <artifactid>gs-rest-service</artifactid> <version>0.1.0</version> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.3.2.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.postgresql</groupid> <artifactid>postgresql</artifactid> <version>9.4-1201-jdbc4</version> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> <repositories> <repository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </repository> </repositories> <pluginrepositories> <pluginrepository> <id>spring-releases</id> <url>https://repo.spring.io/libs-release</url> </pluginrepository> </pluginrepositories> </project>
my src/main/java/quotes/application.java
file:
package quotes; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class application { public static void main(string[] args) { springapplication.run(application.class, args); } }
my src/main/java/quotes/quote.java
file:
package quotes; public class quote { private string content; private string author; public quote(string content, string author) { this.content = content; this.author = author; } public string getcontent() { return this.content; } public quote setcontent(string content) { this.content = content; return this; } public string getauthor() { return this.author; } public quote setauthor(string author) { this.author = author; return this; } }
and src/main/java/quotes/quotecontroller.java
file:
package quotes; import java.util.concurrent.atomic.atomiclong; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestparam; import org.springframework.web.bind.annotation.responsebody; import org.springframework.web.bind.annotation.crossorigin; @controller public class quotecontroller { private static final string template = "hello, %s!"; private final atomiclong counter = new atomiclong(); @crossorigin(origins = "*") @requestmapping("/random") public @responsebody quote randomquote() { return new quote("¿a dónde vas? patatas traigo", "ortega y pacheco"); } }
i can build , run application maven:
mvn clean package java -jar target/*.jar
the idea modify code on quotecontroller.java
connect postgresql , return random stored quote.
could please give advices / clues?
you should try tutorial .
http://devcrumb.com/hibernate/spring-data-jpa-hibernate-maven
Comments
Post a Comment