请勿使用 WebLogic TransactionHelper getUserTransaction 方法

此规则会标记是否使用了 weblogic.transaction.TransactionHelper getUserTransaction() 设置。 该方法实现必须迁移,才能在 WebSphere Application Server 上进行使用。

解决方案

请使用以下代码而不是特定于 WebLogic 的 getUserTransaction() 方法。

public static UserTransaction getUserTransaction() {
UserTransaction txn = null;
try {
Properties params = getInitialContextProperties();
javax.naming.InitialContext ctx = 新的 javax.naming.InitialContext(params);
      txn = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
} catch(Throwable t) {
t.printStackTrace();
}
return txn;

}

public static Properties getInitialContextProperties() {
Properties props = new Properties();

props.put(上下文。INITIAL_CONTEXT_FACTORY , getInitialContextFactoryName ());
props.put(上下文。URL_PKG_PREFIXES , "com.ibm.ws.runtime:com.ibm.ws.naming");
props.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");
return props;
}

有关更多信息,请参阅 Global Transactions for Network Deployment