-
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.
Browse files
Browse the repository at this point in the history
Feat : Custom property Source를 추가합니다.
- Loading branch information
Showing
7 changed files
with
56 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sopt.gptapi.config; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Setter | ||
@Getter | ||
@Component | ||
@ConfigurationProperties(prefix = "app") | ||
@EnableConfigurationProperties(PromptProperty.class) | ||
@PropertySource(value = "classpath:prompt.yml", factory = YamlPropertySourceFactory.class) | ||
@Configuration | ||
public class PromptProperty { | ||
|
||
private String prompt; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/sopt/gptapi/config/YamlPropertySourceFactory.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,22 @@ | ||
package org.sopt.gptapi.config; | ||
|
||
import io.micrometer.common.lang.Nullable; | ||
import java.util.Objects; | ||
import java.util.Properties; | ||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | ||
import org.springframework.core.env.PropertiesPropertySource; | ||
import org.springframework.core.env.PropertySource; | ||
import org.springframework.core.io.support.EncodedResource; | ||
import org.springframework.core.io.support.PropertySourceFactory; | ||
|
||
public class YamlPropertySourceFactory implements PropertySourceFactory { | ||
|
||
@Override | ||
public PropertySource<?> createPropertySource(String name, EncodedResource resource){ | ||
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); | ||
factory.setResources(resource.getResource()); | ||
|
||
Properties properties = factory.getObject(); | ||
return new PropertiesPropertySource(resource.getResource().getFilename(), properties); | ||
} | ||
} |
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
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