我对 Micronaut 应用程序的 application.yml 中的两个不同数据源有以下定义 -
datasources:
default:
url: <jdbc-url>
driverClassName: org.postgresql.Driver
username: <username>
password: <password>
dialect: POSTGRES
schema: <schema>
ms-sql:
url: <jdbc-url>
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
username: <username>
password: <password>
dialect: org.hibernate.dialect.SQLServer2012Dialect
schema: <schema>
如何在下面的服务类中注入 EntityMananger 的特定实例?
服务类片段:
@Inject
private EntityManager em;
@Transactional
@Override
public int callSP(int num) {
StoredProcedureQuery query = em.createStoredProcedureQuery("storelist.testSP1")
.registerStoredProcedureParameter("InputInt", Integer.class, ParameterMode.IN)
.registerStoredProcedureParameter("OutputInt", Integer.class, ParameterMode.OUT)
.setParameter("InputInt", num);
query.execute();
Integer result = (Integer) query.getOutputParameterValue("OutputInt");
return result;
}