gradle / groovy springbooot 3.5.8
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.8' // 혹시 에러나면 3.4.0 권장
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.ai'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
}
ext {
set('springAiVersion', "1.1.0-M3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.ai:spring-ai-starter-model-vertex-ai-gemini'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
package com.ai.springai.controller;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
@RequestMapping("/api")
@RestController
public class ChatController {
private final VertexAiGeminiChatModel vertexAiGeminiChatModel;
public ChatController( VertexAiGeminiChatModel vertexAiGeminiChatModel) {
this.vertexAiGeminiChatModel = vertexAiGeminiChatModel;
}
@GetMapping("/chat")
public Map<String, String> chat(@RequestBody String message) {
Map<String, String> responses = new HashMap<>();
String vertexAiGeminiResponse = vertexAiGeminiChatModel.call(message);
responses.put("vertexai(gemini) 응답", vertexAiGeminiResponse);
return responses;
}
}
spring:
ai:
vertex:
ai:
gemini:
project-id: //프로젝트 아이디 적어주세요
location: us-central1
환경 설정 컨트롤러 하나 만들었습니다
postman으로테스트해보면

참고한 블로그
[Spring Boot3] Spring AI를 활용한 초간단 Chat Model API 🗣️구현하기 (Gemini, ChatGPT)
ChatGPT, Gemini 같은 생성형 AI를 호출할 때 직접 API URL을 호출해서 구현하는 방식보다 더 효율적으로, 더 쉽게 구현할 수는 없을까? 위 질문의 해답이 될 'Spring AI'가 무엇인지 알아보자
velog.io
https://github.com/cookiboii/springai.git
GitHub - cookiboii/springai
Contribute to cookiboii/springai development by creating an account on GitHub.
github.com
제 소스 코드입니다restful 방식으로 코드를 짰고
https://github.com/cookiboii/springai-with-nextjs.git
GitHub - cookiboii/springai-with-nextjs
Contribute to cookiboii/springai-with-nextjs development by creating an account on GitHub.
github.com
프론트는 사실 제미나이 cli써서 짰습니다 참고하세요 껍데기만 만들었습니다
'개발 공부 > Java-Spring' 카테고리의 다른 글
| [JPA] N+1 문제, 원인과 결과로 완벽하게 이해하기 (0) | 2026.01.20 |
|---|---|
| 불변의 객체 의 정의 (0) | 2025.12.10 |
| 객체 지향 프로그래밍(OOP)의 특징 (0) | 2025.11.22 |
| 객체의 종류 (0) | 2025.11.20 |
| 자바 예약어 final vs static (0) | 2025.10.23 |