[백업][가리사니] spring .yml (yaml) 기본설정방법
java, spring

이 문서는 가리사니 개발자 포럼에 올렸던 글의 백업 파일입니다. 오래된 문서가 많아 현재 상황과 맞지 않을 수 있습니다.

스프링 시큐리티 OAUTH 강의에서 이부분을 설명하지 프로퍼티로 처리했는데 추가로 달아봅니다.

YAML

@Bean
public static PropertySourcesPlaceholderConfigurer properties()
{
	PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
	YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
	yaml.setResources(new ClassPathResource("classpath로부터경로주소.yml"));
	propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
	return propertySourcesPlaceholderConfigurer;
}

예제

@Bean
@ConfigurationProperties("facebook.client")
AuthorizationCodeResourceDetails facebook()
{
	return new AuthorizationCodeResourceDetails();
}

@Bean
@ConfigurationProperties("facebook.resource")
ResourceServerProperties facebookResource()
{
	return new ResourceServerProperties();
}

프로퍼티 방식

facebook.client.clientId: 발급받은 클라이언트 아이디
facebook.client.clientSecret: 발급받은 시크릿 
facebook.client.accessTokenUri: https://graph.facebook.com/oauth/access_token
facebook.client.userAuthorizationUri: https://www.facebook.com/dialog/oauth
facebook.client.tokenName: oauth_token
facebook.client.authenticationScheme: query
facebook.client.clientAuthenticationScheme: form
facebook.client.scope: public_profile,email,user_birthday
facebook.resource.userInfoUri: https://graph.facebook.com/me

YAML 방식

facebook:
  client:
    clientId: 발급받은 클라이언트 아이디
    clientSecret: 발급받은 시크릿 
    accessTokenUri: https://graph.facebook.com/oauth/access_token
    userAuthorizationUri: https://www.facebook.com/dialog/oauth
    tokenName: oauth_token
    authenticationScheme: query
    clientAuthenticationScheme: form
    scope: public_profile,email,user_birthday
  resource:
    userInfoUri: https://graph.facebook.com/me

추신

워낙 단순한거라 강의로 쓸게 없어서 이렇게 써봅니다...