I am working on a Spring based project that is (so-far) completely XML-free, except now I\'ve hit a wall with the Spring JPA repository populator:
It's straight-forward actually:
@Configuration
class ApplicationConfig {
@Bean
public JacksonRepositoryPopulatorFactoryBean repositoryPopulator() {
Resource sourceData = new ClassPathResource("test-data.json");
JacksonRepositoryPopulatorFactoryBean factory = new JacksonRepositoryPopulatorFactoryBean();
// Set a custom ObjectMapper if Jackson customization is needed
factory.setObjectMapper(…);
factory.setResources(new Resource[] { sourceData });
return factory;
}
}
By returning the FactoryBean
itself, Spring will take care of invoking all the necessarry callback interfaces (i.e. setApplicationContext(…)
, setBeanClassLoader(…)
etc.). The factory bean is an ApplicationListener
and thus will listen to the ContextRefreshedEvent
and trigger population when the ApplicationContext
is fully initialized.