I am very new to developing enterprise applications using Java EE. I have been using jdeveloper for this. Although I have gone through some books, I am still finding it difficult to understand the practical use and benefit of some modules.
It would be great if you anybody could answer some questions (written below the code) regarding annotations.
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;
}
}
In the above code,
@EJB
StudentSession mySession;
Then I use,
mySession.saveStudentInfo(rqst.getName(), rqst.getAddr(), rqst.getClass_(), rqst.getGrade());
i.e. i am using mySession to access a method of StudentSession. Now, what benefit is the @EJB
annotations doing here is not clear to me.
@Resource
SessionContext sessionContext;
I haven't seen the use of sessionContext anywhere in the code except the declaration.
And what does the @Resource
meaning here.