2

I started emulator by this line:

gcloud beta emulators datastore start --host-port=localhost:8484 --no-store-on-disk

of course i can define com.google.cloud.datastore.Datastore and create instance by this lines:

            return DatastoreOptions.newBuilder()
                .setHost("http://localhost:8484")
                .setProjectId("analytics-project")
                .build()
                .getService();

but how to force spring-gcp repositories to use emulator datastore?

Example of repository class:

import org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository;

import java.util.List;

public interface AnalyticsUserRepo extends DatastoreRepository<AnalyticsUser, String> {

    List<AnalyticsUser> findByEmail(String email);

}
Alexey Alexeenka
  • 891
  • 12
  • 15

1 Answers1

4

You have to add these lines to your application.properties file:

spring.cloud.gcp.datastore.project-id=YOUR_PROJECT_ID
spring.cloud.gcp.datastore.emulator.enabled=true
spring.cloud.gcp.datastore.emulator.port=YOUR_DATASTORE_EMULATOR_PORT
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
C.Godefroy
  • 61
  • 1
  • 7