Skip to content

Commit

Permalink
⚡ : profile 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed Mar 11, 2024
1 parent 5dfbc99 commit ea8159f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/example/runway/RunwayApplication.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package com.example.runway;

import java.util.Arrays;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;

@SpringBootApplication
@Slf4j
@OpenAPIDefinition(servers = {@Server(url = "${server.servlet.context-path}", description = "Default Server URL")})
public class RunwayApplication {
public class RunwayApplication implements ApplicationListener<ApplicationReadyEvent> {
private final Environment environment;

public RunwayApplication(Environment environment) {
this.environment = environment;
}

public static void main(String[] args) {
SpringApplication.run(RunwayApplication.class, args);
long heapSize = Runtime.getRuntime().totalMemory();
System.out.println("HEAP Size(M) : "+ heapSize / (1024*1024) + " MB");
log.info("HEAP Size(M) : "+ heapSize / (1024*1024) + " MB");
}
@Override
public void onApplicationEvent(ApplicationReadyEvent event){
log.info("applicationReady status Active Profiles =" + Arrays.toString(environment.getActiveProfiles()));
}

}
18 changes: 16 additions & 2 deletions src/main/java/com/example/runway/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
Expand All @@ -22,18 +25,30 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;

import io.lettuce.core.ClientOptions;
import io.lettuce.core.SocketOptions;

@Configuration
@EnableRedisRepositories
public class RedisConfig {
private final Environment environment;

private static final String LOCAL = "local";
@Value("${spring.redis.host}")
private String host;

@Value("${spring.redis.port}")
private int port;

public RedisConfig(Environment environment) {
this.environment = environment;
}

@Bean
public RedisConnectionFactory redisConnectionFactory() {

if(environment.getActiveProfiles()[0].equals(LOCAL)) {
return new LettuceConnectionFactory(host, port);
}
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.clusterNode(host, port);
LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder()
Expand All @@ -42,7 +57,6 @@ public RedisConnectionFactory redisConnectionFactory() {
.connectTimeout(Duration.ofMillis(1000L)).build())
.build())
.commandTimeout(Duration.ofSeconds(1000L)).build();
//return new LettuceConnectionFactory(host, port);
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
}

Expand Down

0 comments on commit ea8159f

Please sign in to comment.