[JAVA] How to set Spring Boot + PostgreSQL



--Enable PostgreSQL with Spring Boot --Make a simple app


--SpringToolSuite 3.8.4 (hereinafter STS)


--Spring Tool Suite installed --PostgreSQL has already been installed (this time, the one installed in the host OS is used)


  1. DB settings
  2. Create a project
  3. Project settings
  4. Create a model controller repository service
  5. Run


Create a DB in advance before creating a project


 (Don't forget to switch databases)
, name VARCHAR(16)
, age INT);
 , (2,'tadokoro',24)
 , (3,'hanako',14);


Create a new project

Create a project using Spring Initializr 1.png

Press the Generate Project button to download the project folder. Then ** unzip ** and leave it wherever you like

Project import

Select the [Directory] button from the File-> Open Projects From File Systems .. on the STS tab and select the project folder you just unzipped. Make sure Import as is Maven and select Finish

Environmental setting

Rewriting pom.xml

Access Spring IO platform springioplatform.png Copy the settings description in QuickStart and add it to your pom.xml



<!--from here-->
<!--So far-->

  <!--Also add the following-->
  <!--Add up to here-->

Add connection information to PostgreSQL



That's all for environment settings

Creating a model


@Table(name = "person")
public class Person {

  private int id;
  private String name;
  private int age;

  public Integer getId() {
    return id;
  public void setId(Integer id) {
    this.id = id;
  public String getName() {
    return name;
  public void setName(String name) {
    this.name = name;
  public int getAge() {
    return age;
  public void setAge(int age) {
    this.age = age;

Creating a repository


public interface PersonRepository extends JpaRepository<Person,Integer>{


Creating a service


public class PersonService {

  PersonRepository repository;
  public List<Person> findAll(){
    return repository.findAll(new Sort(Sort.Direction.ASC,"id"));

Creating a controller


public class PersonController {
  PersonService service;
  public List<Person> index(){
    return service.findAll();


Select a project and right click Run as -> Spring Boot App zikkoukekka.png

If it is displayed as above, it is OK

Reference site

https://www.slideshare.net/shintanimoto/spring-boot10 http://dev.classmethod.jp/server-side/java/using_spring_boot_2/

Sample project


Recommended Posts

How to set Spring Boot + PostgreSQL
Spring Boot --How to set session timeout time
How to use ModelMapper (Spring boot)
How to split Spring Boot message file
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
How to make Spring Boot Docker Image smaller
How to use Spring Boot session attributes (@SessionAttributes)
How to add a classpath in Spring Boot
How to bind to property file in Spring Boot
[Spring Boot] How to refer to the property file
Set context-param in Spring Boot
Introduction to Spring Boot ① ~ DI ~
How to set Docker nginx
Introduction to Spring Boot ② ~ AOP ~
How to set Java constants
Set cookies with Spring Boot
Introduction to Spring Boot Part 1
How to write a unit test for Spring Boot 2
How to create a Spring Boot project in IntelliJ
[Spring Boot] How to create a project (for beginners)
How to use CommandLineRunner in Spring Batch of Spring Boot
How to boot by environment with Spring Boot of Maven
How to set environment variables in the properties file of Spring boot application
How to use Lombok in Spring
How to unit test Spring AOP
Spring Boot + PostgreSQL error resolution method
How to change application.properties settings at boot time in Spring boot
How to use Spring Data JDBC
[How to install Spring Data Jpa]
How to call and use API in Java (Spring Boot)
Upgrade spring boot from 1.5 series to 2.0 series
How to set Lombok in Eclipse
How to control transactions in Spring Boot without using @Transactional
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
How to create your own Controller corresponding to / error with Spring Boot
How to set and use profile in annotation-based Configuration in Spring framework
How to make CsrfRequestDataValueProcessor and original RequestDataValueProcessor coexist on Spring Boot
Set Spring Security authentication result to JSON
[Introduction to Spring Boot] Form validation check
How to include Spring Tool in Eclipse 4.6.3?
Story when moving from Spring Boot 1.5 to 2.1
How to set up and use kapt
[Java] How to set the Date time to 00:00:00
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
How to set JAVA_HOME with Maven appassembler-maven-plugin
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
[Spring MVC] How to pass path variables
Needed for iOS 14? How to set NSUserTrackingUsageDescription
How to write Spring AOP pointcut specifier
Add spring boot and gradle to eclipse
How to apply thymeleaf changes to the browser immediately with #Spring Boot + maven
[Spring Boot] I investigated how to implement post-processing of the received request.
How to read Body of Request multiple times with Spring Boot + Spring Security
How to deploy
Challenge Spring Boot
[Spring Boot Actuator] How to manually register your own health check process
How to not start Flyway when running unit tests in Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot