thêm docker file. test còn lỗi docker compose không connect được mongodb và redis. chạy trên IDE thì connect local thành công.

This commit is contained in:
2026-01-20 16:48:25 +07:00
parent e912928597
commit c0dd57501e
13 changed files with 143 additions and 57 deletions

View File

@@ -1,4 +1,12 @@
# ===== BUILD STAGE =====
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /build
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests
# ===== RUN STAGE =====
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
COPY --from=build /build/target/*.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

View File

@@ -1,22 +1,22 @@
package com.dken.giftCodeService.config;
// package com.dken.giftCodeService.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.data.redis.connection.RedisConnectionFactory;
// import org.springframework.data.redis.core.RedisTemplate;
// import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
// @Configuration
// public class RedisConfig {
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory factory) {
// @Bean
// public RedisTemplate<String, String> redisTemplate(
// RedisConnectionFactory factory) {
RedisTemplate<String, String> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
return template;
}
}
// RedisTemplate<String, String> template = new RedisTemplate<>();
// template.setConnectionFactory(factory);
// template.setKeySerializer(new StringRedisSerializer());
// template.setValueSerializer(new StringRedisSerializer());
// return template;
// }
// }

View File

@@ -0,0 +1,14 @@
server:
port: 8602
spring:
application:
name: gift-code-service
data:
mongodb:
host: mongodb
port: 27017
database: gift-codedb
redis:
host: redis
port: 6379

View File

@@ -1 +0,0 @@
spring.application.name=demo

View File

@@ -6,8 +6,9 @@ spring:
name: gift-code-service
data:
mongodb:
uri: mongodb://localhost:27017/gift-codedb
auto-index-creation: true
host: localhost
port: 27017
database: gift-codedb
redis:
host: localhost
port: 6379