在Wildfly 10独立模式下,我使用以下代码段获取SessionContext对象
InitialContext context = new InitialContext();
UserTransaction userTrans = null;
userTrans = (UserTransaction) m_Context.lookup("java:jboss/UserTransaction");
userTrans.setTransactionTimeout(600000);
然后在SLSB中我使用
@Resource
protected SessionContext sessionontext;
但是在DOMAIN模式下执行相同的代码时,它无法使用SessionContext,因为它的值为null。
更新
@Stateless(mappedName="AppManager")
@Local(value = AppManager.class)
@Remote(value = AppManagerRemote.class)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class AppManagerBean extends AppManagerAdapter implements AppManagerRemote
{
try
{
}
catch(Exp..)
{
sessionontext.setRollbackOnly(); ///Here sessionontext is null
}
}
public class AppManagerAdapter
{
@Resource
protected SessionContext sessionontext;
//
}
答案 0 :(得分:0)
SessionContext注入应该在无状态bean本身。 好动了
name = input("What is your name? ")
age = float(input("How old are you? "))
answer1 = (age + "!? That's very old, " + name + "!")
answer2 = (age + "? You're still young, " + name + ".")
if age > 60:
print(answer1)
if age < 60:
print(answer2)
从AppManagerAdapter到AppManagerBean,然后就可以了。