Skip to content

Commit

Permalink
#2 - Feat : AppConfig 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Oct 17, 2022
1 parent f22a37f commit ecaccc7
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.example.mutbooks.app;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {
@Getter
private static ApplicationContext context;
private static String activeProfile;
@Getter
private static String siteName;
@Getter
private static String siteBaseUrl;

@Autowired
public void setContext(ApplicationContext context) {
AppConfig.context = context;
}

@Value("${spring.profiles.active:}")
public void setActiveProfile(String value) {
activeProfile = value;
}

@Value("${custom.site.name}")
public void setSiteName(String siteName) {
AppConfig.siteName = siteName;
}

@Value("${custom.site.baseUrl}")
public void setSiteBaseUrl(String siteBaseUrl) {
AppConfig.siteBaseUrl = siteBaseUrl;
}

public static boolean isNotProd() {
return isProd() == false;
}

public static boolean isProd() {
return activeProfile.equals("prod");
}

public static boolean isNotDev() {
return isLocal() == false;
}

public static boolean isLocal() {
return activeProfile.equals("local");
}

public static boolean isNotTest() {
return isLocal() == false;
}

public static boolean isTest() {
return activeProfile.equals("test");
}

@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}
}

0 comments on commit ecaccc7

Please sign in to comment.