Algomate#1 - 내 정답과 유사한 알고리즘의 정답을 추천해준다고??!

2025. 1. 30. 22:55·AlgoMate

오늘부터 내가 다시 spring으로 이전하고 있는 프로젝트의 진행을 만들어보려고 한다.

## 오늘은 스프링 어플리케이션을 postgres와 연결하는 걸 만들어보겠다

 

우선 도커가 설치돼있어야한다.

docker run -d \
  --name my-postgres \
  -e POSTGRES_USER=your_username \
  -e POSTGRES_PASSWORD=your_password \
  -e POSTGRES_DB=your_database_name \
  -p 5432:5432 \
  postgres:latest

 

-> 포스트 그레스 설치

application.yml

이제 application.properties나 application.yaml에 db 연결 정보를 넣어주면 된다.

 

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/db_name
    username: your_username
    password: your_password
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect

 

나처럼 dev 와 product를 나눴다면

spring:
  profiles:
    active: dev

 

테스트를 위해 간단한 

코드를 만들어보았다.

 

package com.algorithm.mate.dbTEST.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
public class DbTest {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping
    public String testConnection() {
        String result = jdbcTemplate.queryForObject("SELECT version()", String.class);
        return "Connected to: " + result;
    }
}

 

이제 

서버를 실행하고 

localhost:8080/api/test 를 실행하면

실행된 화면

'AlgoMate' 카테고리의 다른 글

Celery + Redis vs Celery + RabbitMQ: 어떤 선택이 더 나을까?  (0) 2025.02.17
🚀 동적으로 파일을 제공하는 방법  (2) 2025.02.16
Spring Boot 단위 테스트: @Mock 과 @InjectionMocks의 원리와 활용  (2) 2025.02.14
AlgoMate#3 - docker 로 띄운 DB 에 접근하기(PostgreSQL)  (2) 2025.02.01
AlgoMate#2 - Jplag를 통한 유사도 검사  (2) 2025.02.01
'AlgoMate' 카테고리의 다른 글
  • 🚀 동적으로 파일을 제공하는 방법
  • Spring Boot 단위 테스트: @Mock 과 @InjectionMocks의 원리와 활용
  • AlgoMate#3 - docker 로 띄운 DB 에 접근하기(PostgreSQL)
  • AlgoMate#2 - Jplag를 통한 유사도 검사
SungHoJung
SungHoJung
  • SungHoJung
    HOLOUD
    SungHoJung
  • 전체
    오늘
    어제
    • 분류 전체보기 (40)
      • AlgoMate (13)
      • TroubleShooting (0)
      • 여러가지 모음집 (4)
      • Infra (17)
  • 링크

    • github
  • 인기 글

  • 태그

    메세지 브로커
    ci-cd
    EC2
    celery+rabbitmq
    docker-compose
    celery+redis
    AWS
    로컬 서버와 통신
    ECS
    host.docker.internal
    컨테이너 간 통신
    redis
    스왑 메모리 설정
    IAM
    recaptcha 우회
    Kubernetes
    크롤링한 데이터
    k8s
    bypass recaptcha
    Celery
  • hELLO· Designed By정상우.v4.10.3
SungHoJung
Algomate#1 - 내 정답과 유사한 알고리즘의 정답을 추천해준다고??!
상단으로

티스토리툴바