I've setup a Spring Data project with two different datasources and am trying to invoke database-specific functions from a single @Controller. I have two separate Entity Managers, Connection Properties and Transaction Managers for each datasource.
Below is my current @Controller
@RequestMapping(value = "/searchDB1", produces="application/json", method = RequestMethod.GET)
public List<Map<String, Object>> getList1() {
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(
"select name, id from db1.Database1"
);
return list;
}
@RequestMapping(value = "/searchDB2", produces="application/json", method = RequestMethod.GET)
public void getList2() {
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(
"select name, id from db2.Database2"
);
}
This will obviously fail as my jdbcTemplate is only wired to a single database at a time - what might be the best way for my controller to choose between databases depending on which method is called (Abstracting to Service Impl, etc.)