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

View File

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