Skip to content

Commit 85007ed

Browse files
authored
h2 오류및 sql 오류 및 기타등등 많은 오류 해결... (#37)
1 parent 4f0a37d commit 85007ed

File tree

7 files changed

+90
-13
lines changed

7 files changed

+90
-13
lines changed

src/main/kotlin/com/back/koreaTravelGuide/common/config/DevConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DevConfig {
4444
println(" 📊 Actuator Info: $baseUrl/actuator/info")
4545

4646
println("\n🔧 데이터베이스 접속 정보 (H2 Console용):")
47-
println(" JDBC URL: jdbc:h2:mem:korea_travel_guide")
47+
println(" JDBC URL: jdbc:h2:mem:testdb")
4848
println(" Username: sa")
4949
println(" Password: (비어있음)")
5050

src/main/kotlin/com/back/koreaTravelGuide/common/exception/GlobalExceptionHandler.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class GlobalExceptionHandler {
4646
ex: Exception,
4747
request: HttpServletRequest,
4848
): ResponseEntity<ApiResponse<Void>> {
49+
// Static resource 예외는 무시 (favicon.ico, CSS, JS 등)
50+
if (ex is org.springframework.web.servlet.resource.NoResourceFoundException) {
51+
logger.debug("Static resource not found: {} at {}", ex.message, request.requestURI)
52+
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponse("리소스를 찾을 수 없습니다"))
53+
}
54+
4955
logger.error("서버 오류 - {}: {} at {}", ex::class.simpleName, ex.message, request.requestURI, ex)
5056
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse("서버 내부 오류가 발생했습니다"))
5157
}

src/main/kotlin/com/back/koreaTravelGuide/common/security/SecurityConfig.kt

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.back.koreaTravelGuide.security.CustomOAuth2UserService
55
import com.back.koreaTravelGuide.security.JwtAuthenticationFilter
66
import org.springframework.context.annotation.Bean
77
import org.springframework.context.annotation.Configuration
8+
import org.springframework.core.env.Environment
89
import org.springframework.security.config.annotation.web.builders.HttpSecurity
910
import org.springframework.security.config.annotation.web.invoke
1011
import org.springframework.security.config.http.SessionCreationPolicy
@@ -16,35 +17,59 @@ class SecurityConfig(
1617
private val customOAuth2UserService: CustomOAuth2UserService,
1718
private val customOAuth2LoginSuccessHandler: CustomOAuth2LoginSuccessHandler,
1819
private val jwtAuthenticationFilter: JwtAuthenticationFilter,
20+
private val environment: Environment,
1921
) {
2022
@Bean
2123
fun filterChain(http: HttpSecurity): SecurityFilterChain {
24+
val isDev = environment.activeProfiles.contains("dev")
25+
2226
http {
23-
// 기본 보안 기능
2427
csrf { disable() }
2528
formLogin { disable() }
2629
httpBasic { disable() }
2730
logout { disable() }
2831

32+
headers {
33+
if (isDev) {
34+
frameOptions { disable() }
35+
} else {
36+
frameOptions { sameOrigin }
37+
}
38+
}
39+
2940
sessionManagement {
30-
sessionCreationPolicy = SessionCreationPolicy.STATELESS
41+
sessionCreationPolicy =
42+
if (isDev) {
43+
SessionCreationPolicy.IF_REQUIRED
44+
} else {
45+
SessionCreationPolicy.STATELESS
46+
}
3147
}
3248

33-
oauth2Login {
34-
userInfoEndpoint {
35-
userService = customOAuth2UserService
49+
if (!isDev) {
50+
oauth2Login {
51+
userInfoEndpoint {
52+
userService = customOAuth2UserService
53+
}
54+
authenticationSuccessHandler = customOAuth2LoginSuccessHandler
3655
}
37-
authenticationSuccessHandler = customOAuth2LoginSuccessHandler
3856
}
3957

4058
authorizeHttpRequests {
41-
authorize("/api/auth/**", permitAll)
42-
authorize("/swagger-ui/**", "/v3/api-docs/**", permitAll)
4359
authorize("/h2-console/**", permitAll)
60+
authorize("/swagger-ui/**", "/v3/api-docs/**", permitAll)
61+
authorize("/api/auth/**", permitAll)
4462
authorize("/favicon.ico", permitAll)
45-
authorize(anyRequest, authenticated)
63+
if (isDev) {
64+
authorize(anyRequest, permitAll)
65+
} else {
66+
authorize(anyRequest, authenticated)
67+
}
68+
}
69+
70+
if (!isDev) {
71+
addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter::class.java)
4672
}
47-
addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter::class.java)
4873
}
4974

5075
return http.build()

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/aiChat/service/AiChatService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.back.koreaTravelGuide.domain.ai.aiChat.entity.AiChatSession
77
import com.back.koreaTravelGuide.domain.ai.aiChat.entity.SenderType
88
import com.back.koreaTravelGuide.domain.ai.aiChat.repository.AiChatMessageRepository
99
import com.back.koreaTravelGuide.domain.ai.aiChat.repository.AiChatSessionRepository
10+
import org.slf4j.LoggerFactory
1011
import org.springframework.ai.chat.client.ChatClient
1112
import org.springframework.ai.chat.memory.ChatMemory
1213
import org.springframework.stereotype.Service
@@ -17,6 +18,8 @@ class AiChatService(
1718
private val aiChatSessionRepository: AiChatSessionRepository,
1819
private val chatClient: ChatClient,
1920
) {
21+
private val logger = LoggerFactory.getLogger(AiChatService::class.java)
22+
2023
fun getSessions(userId: Long): List<AiChatSession> {
2124
return aiChatSessionRepository.findByUserIdOrderByCreatedAtDesc(userId)
2225
}
@@ -74,6 +77,7 @@ class AiChatService(
7477
.call()
7578
.content() ?: AI_ERROR_FALLBACK
7679
} catch (e: Exception) {
80+
logger.error("AI 응답 생성 실패: {}", e.message, e)
7781
AI_ERROR_FALLBACK
7882
}
7983

src/main/resources/application.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
spring:
22
profiles:
33
active: dev
4+
config:
5+
import: "optional:file:.env[.properties]"
46

57
# Spring AI 1.0.0-M6 설정 (OpenRouter 사용)
68
ai:
@@ -14,7 +16,7 @@ spring:
1416

1517
# 개발용 H2 Database 설정 (주니어 개발자용)
1618
datasource:
17-
url: jdbc:h2:mem:korea_travel_guide
19+
url: jdbc:h2:mem:testdb
1820
driver-class-name: org.h2.Driver
1921
username: sa
2022
password: ""
@@ -34,6 +36,11 @@ spring:
3436
hibernate:
3537
format_sql: true # SQL 포맷팅
3638

39+
sql:
40+
init:
41+
mode: always
42+
schema-locations: classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-h2.sql
43+
3744
# WebSocket 설정 (Guest-Guide 채팅용)
3845
websocket:
3946
allowed-origins: "http://localhost:3000,http://localhost:3001,http://localhost:8080"
@@ -63,6 +70,12 @@ spring:
6370
session:
6471
store-type: none # Redis 없어도 실행 가능하도록 변경
6572
timeout: 30m
73+
74+
# Redis 자동 설정 비활성화 (세션 비활성화용)
75+
autoconfigure:
76+
exclude:
77+
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
78+
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
6679

6780
# Swagger API 문서 설정 (주니어 개발자용)
6881
springdoc:
@@ -79,6 +92,12 @@ weather:
7992
key: ${WEATHER_API_KEY}
8093
base-url: http://apis.data.go.kr/1360000/MidFcstInfoService
8194

95+
# Tour API 설정
96+
tour:
97+
api:
98+
key: ${TOUR_API_KEY:dev-tour-api-key-placeholder}
99+
base-url: ${TOUR_API_BASE_URL:http://apis.data.go.kr/B551011/KorService1}
100+
82101

83102
# 로깅 설정 (주니어 개발자 디버깅용)
84103
logging:
@@ -111,4 +130,5 @@ management:
111130

112131
# JWT 설정
113132
jwt:
114-
secret-key: ${CUSTOM__JWT__SECRET_KEY}
133+
secret-key: ${CUSTOM__JWT__SECRET_KEY:dev-secret-key-for-local-testing-please-change}
134+
access-token-expiration-minutes: ${JWT_ACCESS_TOKEN_EXPIRATION_MINUTES:60}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS SPRING_AI_CHAT_MEMORY (
2+
id VARCHAR(255) DEFAULT RANDOM_UUID() PRIMARY KEY,
3+
conversation_id VARCHAR(255) NOT NULL,
4+
type VARCHAR(50) NOT NULL,
5+
content CLOB NOT NULL,
6+
metadata CLOB,
7+
"timestamp" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
8+
);
9+
10+
CREATE INDEX IF NOT EXISTS idx_spring_ai_chat_memory_conversation_id ON SPRING_AI_CHAT_MEMORY(conversation_id);
11+
CREATE INDEX IF NOT EXISTS idx_spring_ai_chat_memory_timestamp ON SPRING_AI_CHAT_MEMORY("timestamp");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS SPRING_AI_CHAT_MEMORY (
2+
id VARCHAR(255) PRIMARY KEY,
3+
conversation_id VARCHAR(255) NOT NULL,
4+
message_type VARCHAR(50) NOT NULL,
5+
content TEXT NOT NULL,
6+
metadata TEXT,
7+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
8+
);
9+
10+
CREATE INDEX IF NOT EXISTS idx_spring_ai_chat_memory_conversation_id ON SPRING_AI_CHAT_MEMORY(conversation_id);
11+
CREATE INDEX IF NOT EXISTS idx_spring_ai_chat_memory_created_at ON SPRING_AI_CHAT_MEMORY(created_at);

0 commit comments

Comments
 (0)