我在这里尝试以下操作:我有一个调用远程 EJB 的 Web 应用程序:
@WebServlet("/token")
@SuppressWarnings("serial")
public class TokenServlet extends HttpServlet {
@EJB
private TokenService tokenService;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Token token = tokenService.getToken();
tokenService.setToken(token);
}
}
服务ejb:
@Stateless
@Remote
public class TokenServiceImpl implements TokenService {
private Token token = new Token();
@Override
public Token getToken() {
System.out.println("class: " + TokenServiceImpl.class
+ ", method: getToken() - " + "token value: '"
+ token.getToken() + "' reference: " + this.token);
return this.token;
}
@Override
public void setToken(Token token) {
boolean referenceEquality = this.token == token;
boolean valueEquality = this.token.equals(token);
System.out.println("class " + TokenServiceImpl.class
+ ", methos: setToken(Token token)");
System.out.println("test for reference equality: " + " " + this.token
+ " == " + token + " --> " + referenceEquality);
System.out.println("test for value equality: " + " " + this.token
+ " equals " + token + " --> " + valueEquality);
this.token = token;
}
webproject(.war) 和 ejbproject(.ear) 分别使用 glassfish-application.xml 条目进行部署:
<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Java EE Application 6.0//EN"
"http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
<pass-by-reference>true</pass-by-reference>
</glassfish-application>
class: class TokenServiceImpl, method: getToken() - token value: '
'default token value' reference: com.ebcont.domain.impl.Token@7fef01a8|#]
class TokenServiceImpl, method: setToken(Token token)|#]
test for reference equality: Token@7fef01a8 == Token@2f4d4e75 --> false|#]
test for value equality: Token@7fef01a8 equals Token@2f4d4e75 --> false|#]
是我出了什么问题,还是不能对远程 EJB 使用引用调用?