我对使用Java EE开发企业应用程序很陌生。我一直在为此使用jdeveloper。虽然我已经读过一些书,但我仍然很难理解某些模块的实际使用和好处。Java EE EJB理解
如果您有人可以回答关于注释的一些问题(写在代码下面),那将是非常棒的。
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless(name = "StudentWSApiBean", mappedName = "RizwanWS-RizwanService-StudentWSApiBean")
@WebService(name = "StudentWSApi", serviceName = "StudentWSApi", portName = "StudentWSApiPort")
public class StudentWSApiBeanBean implements StudentWSApiBean {
@Resource
SessionContext sessionContext;
@EJB
StudentSession mySession;
public StudentWSApiBeanBean()
{
}
@WebMethod
public StudentResponse saveStudentInfo(@WebParam(name = "arg0")
StudentRequest rqst)
{
StudentResponse resp = new StudentResponse();
resp.setStat(0);
try
{
int ret = mySession.saveStudentInfo(rqst.getName(), rqst.getAddr(), rqst.getClass_(), rqst.getGrade());
resp.setStat(ret);
}catch(Exception exc)
{
}
return resp;
}
}
在上面的代码,
@EJB
StudentSession mySession;
然后我使用,
mySession.saveStudentInfo(rqst.getName(), rqst.getAddr(), rqst.getClass_(), rqst.getGrade());
即我使用MySession的访问StudentSession的方法。现在,在这里做@EJB
注释有什么好处,我不清楚。
@Resource
SessionContext sessionContext;
我还没有看到使用sessionContext除了声明的代码中的任何地方。 这里的@Resource
是什么意思。
因为没有使用SessionContext,所以它真的很夸张。至于EJB注释,网上有很多参考资料。如果您已经查看过,并对细节有疑问,请将它们发布到此处,但SO不是个人研究助理。 – kostja