0

Spring Data KeyValue looks great for quickly knocking up a mock microservice. How can I bootstrap it with data?

I tried adding stuff to the KeyValueAdapter, but by specifying the bean myself, I've ended up with Repositorys that have been wired with a different KeyValueAdapter, and so don't have the data available.

@Configuration @EnableMapRepositories public class PersistenceConfig { @Bean public KeyValueAdapter keyValueAdapter() { KeyValueAdapter adapter = new MapKeyValueAdapter(ConcurrentHashMap.class); Account testAccount = new Account(); testAccount.id = "dj-asc-test"; testAccount.givenName = "Gertrude"; adapter.put(testAccount.id, testAccount, "accounts"); Account read = (Account) adapter.get("dj-asc-test", "accounts"); Assert.notNull(read); return adapter; } } 

1 Answer 1

1

I guess you'd rather use a repository as the adapter is basically in place to plug other Map implementations. Assume you have a PersonRepository like this:

interface PersonRepository extends CrudRepository<Person, Long> { … } 

Then this should work:

@Configuration @EnableMapRepositories class Application { @Autowired PersonRepository repository; @PostConstruct public void init() { repository.save(new Person(…)); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - I think I'd misunderstood the role of the adapter.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.