-
Notifications
You must be signed in to change notification settings - Fork 2
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
10 changed files
with
265 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jikgong.global.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class CorsConfig { | ||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration config = new CorsConfiguration(); | ||
|
||
config.setAllowCredentials(true); | ||
config.setAllowedOrigins(List.of("http://localhost:8080rrrrrr")); | ||
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); | ||
config.setAllowedHeaders(List.of("*")); | ||
config.setExposedHeaders(List.of("*")); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", config); | ||
return source; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/jikgong/global/config/P6SpySqlFormatter.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,38 @@ | ||
package jikgong.global.config; | ||
|
||
import com.p6spy.engine.logging.Category; | ||
import com.p6spy.engine.spy.P6SpyOptions; | ||
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; | ||
import jakarta.annotation.PostConstruct; | ||
import org.hibernate.engine.jdbc.internal.FormatStyle; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Locale; | ||
|
||
@Configuration | ||
public class P6SpySqlFormatter implements MessageFormattingStrategy { | ||
|
||
@PostConstruct | ||
public void setLogMessageFormat() { | ||
P6SpyOptions.getActiveInstance().setLogMessageFormat(this.getClass().getName()); | ||
} | ||
|
||
@Override | ||
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { | ||
sql = formatSql(category, sql); | ||
return String.format("[%s] | %d ms | %s", category, elapsed, formatSql(category, sql)); | ||
} | ||
|
||
private String formatSql(String category, String sql) { | ||
if (sql != null && !sql.trim().isEmpty() && Category.STATEMENT.getName().equals(category)) { | ||
String trimmedSQL = sql.trim().toLowerCase(Locale.ROOT); | ||
if (trimmedSQL.startsWith("create") || trimmedSQL.startsWith("alter") || trimmedSQL.startsWith("comment")) { | ||
sql = FormatStyle.DDL.getFormatter().format(sql); | ||
} else { | ||
sql = FormatStyle.BASIC.getFormatter().format(sql); | ||
} | ||
return sql; | ||
} | ||
return sql; | ||
} | ||
} |
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,38 @@ | ||
package jikgong.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate() { | ||
// redisTemplate를 받아와서 set, get, delete를 사용 | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
// setKeySerializer, setValueSerializer 설정 | ||
// redis-cli을 통해 직접 데이터를 조회 시 알아볼 수 없는 형태로 출력되는 것을 방지 | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
|
||
return redisTemplate; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/jikgong/global/config/RestTemplateConfig.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,14 @@ | ||
package jikgong.global.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
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 jikgong.global.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class S3Config { | ||
@Value("${cloud.aws.credentials.access-key}") | ||
private String accessKey; | ||
@Value("${cloud.aws.credentials.secret-key}") | ||
private String secretKey; | ||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials awsCredentials= new BasicAWSCredentials(accessKey, secretKey); | ||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | ||
.build(); | ||
} | ||
} |
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,38 @@ | ||
package jikgong.global.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Arrays; | ||
|
||
@OpenAPIDefinition( | ||
info = @Info(title = "tickerBell API 명세서", | ||
description = "tickerBell API 명세서입니다.", | ||
version = "v1")) | ||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
/** | ||
* http://localhost:8080/swagger-ui/index.html | ||
*/ | ||
|
||
// JWT + swagger | ||
@Bean | ||
public OpenAPI openAPI(){ | ||
SecurityScheme securityScheme = new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER).name("Authorization"); | ||
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth"); | ||
|
||
return new OpenAPI() | ||
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) | ||
.security(Arrays.asList(securityRequirement)); | ||
} | ||
|
||
} |
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,5 @@ | ||
spring: | ||
data: | ||
redis: | ||
host: localhost | ||
port: 6379 |
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,51 @@ | ||
spring: | ||
profiles: | ||
active: ${environment} | ||
|
||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: ${DB_ENDPOINT} | ||
username: ${DB_USERNAME} | ||
password: ${DB_PASSWORD} | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
default_batch_fetch_size: 1000 | ||
dialect: org.hibernate.dialect.MySQLDialect | ||
|
||
# 배치 관련 설정 | ||
# batch: | ||
# jdbc: | ||
# initialize-schema: always # batch repo 테이블 자동 생성 | ||
# job: | ||
# enabled: false # 시작과 동시에 실행되는 것 방지 | ||
|
||
app: | ||
auth: | ||
secret-key: ${SECRET_KEY} | ||
|
||
cloud: | ||
aws: | ||
credentials: | ||
access-key: ${S3_ACCESS_KEY} | ||
secret-key: ${S3_SECRET_ACCESS_KEY} | ||
s3: | ||
bucket: tickerbell-image | ||
stack.auto: false #기본 cloudFormation 구성 시작 사용 x | ||
region: | ||
static: ap-northeast-2 | ||
|
||
# sms 관련 설정 | ||
#naver-cloud-sms: | ||
# accessKey: ${SMS_ACCESS_KEY} | ||
# secretKey: ${SMS_SECRET_KEY} | ||
# serviceId: ${SMS_SERVICE_ID} | ||
# senderPhone: ${SMS_SENDER_PHONE} | ||
|
||
# 네이버 지도 관련 설정 | ||
#naver-cloud-map: | ||
# api-key-id: ${MAP_API_KEY_ID} | ||
# api-key: ${MAP_API_KEY} |