Skip to content

Commit

Permalink
[feat] env properties 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason9789 committed Dec 3, 2022
1 parent 81f758f commit aad387c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ build/

### MAC ###
.DS_Store


### properties ###
env.properties
39 changes: 39 additions & 0 deletions src/main/java/com/mab/config/AWSConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mab.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;

@Configuration
@Profile("aws")
public class AWSConfig {

/**
* Key는 중요 정보이기 때문에 properties 파일에 저장한 뒤 가져와 사용하는 방법이 좋다.
*/

@Value("${cloud.aws.credentials.accessKey}")
private String iamAccessKey;

@Value("${cloud.aws.credentials.secretKey}")
private String iamSecretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3Client amazonS3Client() {
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(iamAccessKey, iamSecretKey);
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.build();
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/mab/config/PropertyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mab.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@PropertySources({
@PropertySource("classpath:properties/env.properties")
})
public class PropertyConfig {

}
8 changes: 3 additions & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ spring.jpa.properties.hibernate.show=true
spring.jpa.properties.hibernate.format_sql=true

# AWS S3 설정
logging.level.com.amazonaws.util.EC2MetadataUtils=ERROR

cloud.aws.credentials.accessKey=AKIA2TGNMEX7CSA66XNV
cloud.aws.credentials.secretKey=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

cloud.aws.s3.bucket=rence
cloud.aws.s3.bucket=meet-a-bwa
cloud.aws.region.static=ap-northeast-2
cloud.aws.stack.auto=false

# multipart 설정
spring.servlet.multipart.max-file-size: 100MB
spring.servlet.multipart.max-request-size: 100MB
spring.servlet.multipart.max-request-size: 100MB

0 comments on commit aad387c

Please sign in to comment.