Alexey Alexeenka
Alexey Alexeenka

Reputation: 921

Spring+GCP Datastore: I use repository and want to configure it to use datastore emulator during development or test

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);

}

Upvotes: 2

Views: 1720

Answers (1)

C.Godefroy
C.Godefroy

Reputation: 61

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

Upvotes: 4

Related Questions