title: Setting GOOGLE_APPLICATION_CREDENTIALS in Spring
body: <p>I'm attempting to use Spring to access files from Google Storage Buckets with the end goal of using MultiResourceItemReader to read in multiple XML files from the bucket.  I currently have Spring working with this process when the XML files are locally on my machine (not GCP)</p>
  
  <p>Now, I want to do the same thing, but instead of XML files on my machine, the files are in a GCP Storage bucket. I can access the bucket contents outside of Spring, one file at at time.  For example this little bit of test code allows me to get access to the bucket and then see the files in the bucket.  In this snippet, I setup the credentials via the JSON key file.  (not an environment variable) </p>
  
  <pre><code>public static void storageDriver() throws IOException {
  // Load credentials from JSON key file. If you can't set the GOOGLE_APPLICATION_CREDENTIALS
  // environment variable, you can explicitly load the credentials file to construct the
  // credentials.
  
      String name = "";
      String bucketName = "";
      String bucketFileName = "";
      String bucketFullPath = "";
      Resource myBucker;
      GoogleCredentials credentials;
      File credentialsPath = new File("mycreds.json");  
      try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
          credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
      }
  
  
      Storage storage = StorageOptions.newBuilder()
              .setCredentials(credentials)
              .setProjectId("myProject")
              .build()
              .getService();
  
      for (Bucket bucket:storage.list().iterateAll()){
          if(bucket.getName().equalsIgnoreCase("myGoogleBucket")){
              bucketName = bucket.getName();
              System.out.println(bucket);
              for (Blob blob : bucket.list().iterateAll()){
                  bucketFileName = blob.getName();
                  bucketFullPath = "gs://"+bucketName+"/"+bucketFileName;
                  System.out.println(bucketFullPath);
  
              }
          }
      };
  </code></pre>
  
  <p>However, when I try to do the following with Spring,  Spring complains that I don't have the <code>GOOGLE_APPLICATION_CREDENTIALS</code> defined.  (which of course I don't since I'm doing it programmatically.</p>
  
  <p>For example,  I'll add</p>
  
  <pre><code>@Value("gs://myGoogleBucket")
  private Resource[] resources;
  </code></pre>
  
  <p>The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable <code>GOOGLE_APPLICATION_CREDENTIALS</code> must be defined pointing to a file defining the credentials.</p>