반응형
생성자에서는 빈, 환경변수 주입이 되지 않았기 때문에 멤버변수, 환경변수를 사용하려면 afterPropertiesSet을 사용하여야 한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | public class GoogleAuthServiceImpl implements GoogleAuthService, InitializingBean { private static final JsonFactory JSON_FACTORY = new JacksonFactory(); private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); @Setter private Scope scope; private GoogleAuthorizationCodeFlow flow; private GoogleCredential serviceCredential; @Override public void afterPropertiesSet() throws Exception { GoogleClientSecrets clientSecrets = null; try { clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(getClass().getResourceAsStream("/client_secret.json"))); flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scope.getUserOauthScope()).setAccessType("online").build(); serviceCredential = GoogleCredential.fromStream(getClass().getResourceAsStream("/service_account.json")) .createScoped(scope.getServiceOauthScope()); } catch (IOException e) { log.error("{}", e.getMessage()); throw new InitFailException(); } } |
반응형