Compare commits

...

1 Commits

Author SHA1 Message Date
dongHyo
86fbb0b474 refactor: 인수 name 사용할 수 있도록 수정 2022-06-16 16:49:22 +09:00
2 changed files with 12 additions and 8 deletions

View File

@@ -5,19 +5,23 @@ 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.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
public class YamlPropertySourceFactory implements PropertySourceFactory {
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) {
Resource resource = encodedResource.getResource();
YamlPropertiesFactoryBean factoryBean = new YamlPropertiesFactoryBean();
factoryBean.setResources(resource);
public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) {
Properties yamlProperties = loadYamlProperties(resource);
String sourceName = StringUtils.hasText(name) ? name : resource.getResource().getFilename();
return new PropertiesPropertySource(Objects.requireNonNull(sourceName), Objects.requireNonNull(yamlProperties));
}
Properties properties = factoryBean.getObject();
return new PropertiesPropertySource(Objects.requireNonNull(resource.getFilename()), Objects.requireNonNull(properties));
private Properties loadYamlProperties(EncodedResource resource) {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(resource.getResource());
return factory.getObject();
}
}

View File

@@ -10,7 +10,7 @@ import org.springframework.context.annotation.PropertySource;
@Getter
@RequiredArgsConstructor
@ConstructorBinding
@ConfigurationProperties("jwt")
@ConfigurationProperties(value = "jwt")
@PropertySource(value = "classpath:application.yml", factory = YamlPropertySourceFactory.class)
public class JwtProperties {