-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
1Week_Mission/mutbooks/src/main/java/com/example/mutbooks/app/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |