0
EJB를 처음 사용합니다. 나는 상태 비 저장 엔터프라이즈 빈의 기능을 이해하려고 노력하고있다. 여기 EJB의 상태 비 저장 엔터프라이즈 세션 Bean의 기능 이해
@Stateless
@LocalBean
public class FlightService implements Serializable {
/**
* Default constructor.
*/
public FlightService() {
// TODO Auto-generated constructor stub
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the from
*/
public String getFrom() {
return from;
}
/**
* @param from the from to set
*/
public void setFrom(String from) {
this.from = from;
}
/**
* @return the to
*/
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
/**
* @return the price
*/
public Integer getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(Integer price) {
this.price = price;
}
/**
* @return the numOfSeats
*/
public Integer getNumOfSeats() {
return numOfSeats;
}
/**
* @param numOfSeats the numOfSeats to set
*/
public void setNumOfSeats(Integer numOfSeats) {
this.numOfSeats = numOfSeats;
}
/**
* @return the airplaneModel
*/
public String getAirplaneModel() {
return airplaneModel;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "FlightService [id=" + id + ", from=" + from + ", to=" + to + ", price=" + price + ", numOfSeats="
+ numOfSeats + ", airplaneModel=" + airplaneModel + "]";
}
/**
* @param airplaneModel the airplaneModel to set
*/
public void setAirplaneModel(String airplaneModel) {
this.airplaneModel = airplaneModel;
}
private Integer id =23467;
private String from="Los Angles";
private String to="London";
private Integer price=400;
private Integer numOfSeats=250;
private String airplaneModel="Boeing 787";
}
가 @EJB 의존성 주입이 사용되는 클래스이다
은 다음의 예를 보라. 내가 왜 감사하겠습니다
"flightService4.setAirplaneModel("cannadian Airlines");"
어떤 도움에 설정된 값을 얻고있다
"flightService.getAirplaneModel()"
를 인쇄 할 때
@EJB
private FlightService flightService;
@EJB
private FlightService flightService1;
@EJB
private FlightService flightService2;
@EJB
private FlightService flightService3;
@EJB
private FlightService flightService4;
@EJB
private FlightService flightService5;
@EJB
private FlightService flightService6;
public FlightDetails() {
super();
System.out.println(flightService);
}
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
response.setContentType("text/html");
flightService.setAirplaneModel("Rishanth");
flightService.setFrom("vijaywada");
flightService.setId(1);
flightService.setNumOfSeats(4);
flightService.setPrice(4);
flightService.setTo("hyderabad");
flightService4.setAirplaneModel("cannadian Airlines");
out.println(flightService.getAirplaneModel());
}
나는 이해합니다.
때문에, 즉 그 어떤 대화 상태가 없습니다. 그리고 BTW가 있더라도, 당신은 flightService4에서 setAirplaneModel을 호출하고, flightService에서 getAirplaneModel을 호출합니다. –
@JBNizet 오식에 사과드립니다. 질문을 다시 방문하십시오. –
다시, bean은 ** stateless **로되어 있습니다. 그래서 어떤 대화 상태도 가질 수 없습니다. 동일한 인스턴스가 두 개의 요청을 동시에 처리하지 않는다면 컨테이너는 모든 요청에 대해 임의의 인스턴스를 자유롭게 재사용 할 수 있습니다. –