-
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.
Merge pull request #2 from imminoglobulin/base-configs
Base configs
- Loading branch information
Showing
11 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
package com.kstech.requeks; | ||
|
||
import com.kstech.requeks.util.DefaultProfileUtil; | ||
import com.kstech.requeks.util.InitializeLogUtil; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
@SpringBootApplication | ||
@EnableSwagger2 | ||
@EnableScheduling | ||
@EnableAsync | ||
public class RequeksApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(RequeksApplication.class, args); | ||
SpringApplication app = new SpringApplication(RequeksApplication.class); | ||
DefaultProfileUtil.addDefaultProfile(app); | ||
Environment env = app.run(args).getEnvironment(); | ||
InitializeLogUtil.logApplicationStartup(env); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/kstech/requeks/config/SecurityConfiguration.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,17 @@ | ||
package com.kstech.requeks.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf().disable().authorizeRequests().anyRequest().permitAll(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/kstech/requeks/config/WebConfigurer.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,28 @@ | ||
package com.kstech.requeks.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
public class WebConfigurer extends WebMvcConfigurerAdapter { | ||
@Primary | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler("swagger-ui.html") | ||
.addResourceLocations("classpath:/META-INF/resources/"); | ||
|
||
registry.addResourceHandler("/webjars/**") | ||
.addResourceLocations("classpath:/META-INF/resources/webjars/"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kstech/requeks/constants/ApplicationConstants.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,16 @@ | ||
package com.kstech.requeks.constants; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public interface ApplicationConstants { | ||
String SPRING_PROFILE_DEVELOPMENT = "dev"; | ||
String SPRING_PROFILE_TEST = "test"; | ||
String SPRING_PROFILE_PRODUCTION = "prod"; | ||
|
||
String SPRING_PROFILE_DEFAULT = "spring.profiles.default"; | ||
|
||
String ZONE_ID = "Europe/Istanbul"; | ||
|
||
List<String> EXCEPT_LOG_METHODS = Arrays.asList("info"); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/kstech/requeks/util/DefaultProfileUtil.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,30 @@ | ||
package com.kstech.requeks.util; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.kstech.requeks.constants.ApplicationConstants.SPRING_PROFILE_DEFAULT; | ||
import static com.kstech.requeks.constants.ApplicationConstants.SPRING_PROFILE_DEVELOPMENT; | ||
|
||
public final class DefaultProfileUtil { | ||
|
||
private DefaultProfileUtil() { | ||
} | ||
|
||
public static void addDefaultProfile(SpringApplication app) { | ||
Map<String, Object> defProperties = new HashMap<>(); | ||
defProperties.put(SPRING_PROFILE_DEFAULT, SPRING_PROFILE_DEVELOPMENT); | ||
app.setDefaultProperties(defProperties); | ||
} | ||
|
||
public static String[] getActiveProfiles(Environment env) { | ||
String[] profiles = env.getActiveProfiles(); | ||
if (profiles.length == 0) { | ||
return env.getDefaultProfiles(); | ||
} | ||
return profiles; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/kstech/requeks/util/InitializeLogUtil.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,41 @@ | ||
package com.kstech.requeks.util; | ||
|
||
import io.micrometer.core.instrument.util.StringUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
@Slf4j | ||
public final class InitializeLogUtil { | ||
public static void logApplicationStartup(Environment env) { | ||
String protocol = "http"; | ||
if (env.getProperty("server.ssl.key-store") != null) { | ||
protocol = "https"; | ||
} | ||
String serverPort = env.getProperty("server.port"); | ||
String contextPath = env.getProperty("server.servlet.context-path"); | ||
if (StringUtils.isBlank(contextPath)) { | ||
contextPath = "/"; | ||
} | ||
String hostAddress = "localhost"; | ||
try { | ||
hostAddress = InetAddress.getLocalHost().getHostAddress(); | ||
} catch (UnknownHostException e) { | ||
log.error("The host name could not be determined, using `localhost` as fallback"); | ||
} | ||
log.info("\n----------------------------------------------------------\n\t" + | ||
"Application '{}' is running! Access URLs:\n\t" + | ||
"Local: \t\t{}://localhost:{}{}\n\t" + | ||
"External: \t{}://{}:{}{}\n\t" + "\n----------------------------------------------------------", | ||
env.getProperty("spring.application.name"), | ||
protocol, | ||
serverPort, | ||
contextPath, | ||
protocol, | ||
hostAddress, | ||
serverPort, | ||
contextPath); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/kstech/requeks/util/ObjectMapperUtils.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,78 @@ | ||
package com.kstech.requeks.util; | ||
|
||
import org.modelmapper.ModelMapper; | ||
import org.modelmapper.convention.MatchingStrategies; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public final class ObjectMapperUtils { | ||
|
||
private static ModelMapper modelMapper; | ||
|
||
/** | ||
* Model mapper property setting are specified in the following block. | ||
* Default property matching strategy is set to Strict see {@link MatchingStrategies} | ||
* Custom mappings are added using {@link ModelMapper#addMappings(PropertyMap)} | ||
*/ | ||
static { | ||
modelMapper = new ModelMapper(); | ||
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); | ||
} | ||
|
||
/** | ||
* Hide from public usage. | ||
*/ | ||
private ObjectMapperUtils() { | ||
} | ||
|
||
/** | ||
* <p>Note: outClass object must have default constructor with no arguments</p> | ||
* | ||
* @param <D> type of result object. | ||
* @param <T> type of source object to map from. | ||
* @param entity entity that needs to be mapped. | ||
* @param outClass class of result object. | ||
* @return new object of <code>outClass</code> type. | ||
*/ | ||
public static <D, T> D map(final T entity, Class<D> outClass) { | ||
if (entity == null ){ | ||
return null; | ||
} | ||
return modelMapper.map(entity, outClass); | ||
} | ||
|
||
/** | ||
* <p>Note: outClass object must have default constructor with no arguments</p> | ||
* | ||
* @param entityList list of entities that needs to be mapped | ||
* @param outCLass class of result list element | ||
* @param <D> type of objects in result list | ||
* @param <T> type of entity in <code>entityList</code> | ||
* @return list of mapped object with <code><D></code> type. | ||
*/ | ||
public static <D, T> List<D> mapAll(final Collection<T> entityList, Class<D> outCLass) { | ||
if (entityList == null){ | ||
return null; | ||
} | ||
|
||
return entityList.stream() | ||
.map(entity -> map(entity, outCLass)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Maps {@code source} to {@code destination}. | ||
* | ||
* @param source object to map from | ||
* @param destination object to map to | ||
*/ | ||
public static <S, D> D map(final S source, D destination) { | ||
if (source == null ){ | ||
return null; | ||
} | ||
modelMapper.map(source, destination); | ||
return destination; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
spring: | ||
application: | ||
name: config-server | ||
data: | ||
mongodb: | ||
uri: ${mongodb.logger.uri:${mongodb.uri:mongodb://localhost:27017}} | ||
database: requeks | ||
|
||
server: | ||
port: 9090 | ||
servlet: | ||
session: | ||
cookie: | ||
http-only: true | ||
|
||
logging: | ||
file: | ||
name: log/requeks.log | ||
|
||
management: | ||
endpoint: | ||
routes: | ||
enabled: true | ||
health: | ||
enabled: true | ||
show-details: always | ||
endpoints: | ||
web: | ||
exposure: | ||
include: "*" |
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,16 @@ | ||
${AnsiColor.BLUE} _ | ||
${AnsiColor.BLUE} | | | ||
${AnsiColor.BLUE} _ __ ___ __ _ _ _ ___| | _____ | ||
${AnsiColor.BLUE}| '__/ _ \/ _` | | | |/ _ \ |/ / __| | ||
${AnsiColor.BLUE}| | | __/ (_| | |_| | __/ <\__ \ | ||
${AnsiColor.BLUE}|_| \___|\__, |\__,_|\___|_|\_\___/ | ||
${AnsiColor.BLUE} | | | ||
${AnsiColor.BLUE} |_| | ||
|
||
${AnsiColor.RED}█ | ||
${AnsiColor.RED}█ | ||
${AnsiColor.RED}█ ${AnsiColor.BLACK}Application Name : ${spring.application.name} | ||
${AnsiColor.RED}█ ${AnsiColor.CYAN}Spring Boot Version : ${spring-boot.formatted-version} | ||
${AnsiColor.RED}█ ${AnsiColor.BRIGHT_BLACK}Java Version : ${java.version} | ||
${AnsiColor.RED}█ | ||
${AnsiColor.RED}█ |