I need to provide a datasource resource with JpaPersistModule
. This data source is equipped with an intuitive click.
Now the problem is that I have to build the module during the configuration phase, but the data source is only available at run time.
I currently have the following code:
public class MyJpaConfigurationModule implements Module {
private Map<String, Object> jpaProperties = new HashMap<>();
private Module jpaModule = new JpaPersistModule("peristenceUnit").properties(jpaProperties);
public void configure(Binder binder) {
binder.requestInjection(this);
binder.install(jpaModule);
}
@Provides @Singleton
public DataSource provideDatasource() {
return .....
}
@Inject
public void setJpaProperties(DataSource dataSource, PersistService persistService) {
jpaProperties.put("dataSource", dataSource);
persistService.start();
}
}
I checked, and it seems that the jpa property map is everywhere introduced by reference, so changes at runtime should become visible, but what if this changes in the future?
What is the correct way to resolve such conflicts?
source
share