Compare commits

..

1 Commits

Author SHA1 Message Date
dongHyo
2d637bbed6 refactor: 정적팩토리메서드 네이밍 통일 2022-06-13 22:44:48 +09:00
2 changed files with 8 additions and 12 deletions

View File

@@ -5,23 +5,19 @@ 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(@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));
}
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) {
Resource resource = encodedResource.getResource();
YamlPropertiesFactoryBean factoryBean = new YamlPropertiesFactoryBean();
factoryBean.setResources(resource);
private Properties loadYamlProperties(EncodedResource resource) {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(resource.getResource());
return factory.getObject();
Properties properties = factoryBean.getObject();
return new PropertiesPropertySource(Objects.requireNonNull(resource.getFilename()), Objects.requireNonNull(properties));
}
}

View File

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