【发布时间】:2015-11-10 15:31:29
【问题描述】:
我正在运行 GlassFish Server 4.1,我想定期调用一个方法,所以我使用 @Schedule,该方法需要一个角色,所以我将 @RunAs 添加到类中。但无论我如何尝试,我都无法让它发挥作用。
@Singleton
@Startup
@RunAs("Tool")
public class Test {
@Resource
private SessionContext ctx;
@Schedule(minute = "*/1", hour = "*")
public void checkExpiringAgreements() {
System.out.println("Has role Tool: " + ctx.isCallerInRole("Tool"));
}
}
每分钟运行一次,但会打印:
Info: Has role Tool: false
如果我有任何头发,我现在就会把它撕掉。为什么这不起作用?
【问题讨论】:
-
我想知道 Glassfish 是否需要对 Tool 角色进行额外配置来指定应该使用哪个特定身份。我知道 WebSphere Application Server 可以:stackoverflow.com/questions/33118280/…。否则,我只能说你对注释的使用看起来是正确的,所以应该可以让它工作。
-
尝试通过
@DeclareRoles({"Tool"})声明你在课堂上的角色。