SpringBoot multi-data source uses EntityManager

Multi-data sources use JPA and EM, or report the default data source report failed to find the table, or the error does not have such an entity, DEBUG debugging is the first EM.I have been troubled by this problem for a long time, and the record is solved:

EntityManagerFactorySecondary refers to the second data source in the Springboot project, which indicates the entity manager that imports the second data source.
@PersistenceContext(unitName="entityManagerFactorySecondary")
EntityManager em;

EntityManager的使用如下:

String sql = " SELECT COUNT(*) FROM msg_examine_producer"+day;
Query query =em.createNativeQuery(sql);
List outData = query.getResultList()

Remember to turn off the entity manager after running out

em.close();