I am trying to perform a JNDI name search using Liberty Application Server.However, It is throwing me a dependency injection issue.Attached is my code
I am getting the following Error:
[ERROR ] SRVE0319E: For the [com.airline.controllers.FlightDetails]
servlet, com.airline.controllers.FlightDetails servlet class was
found, but a resource injection failure has occurred. CWNEN0030E: The
server was unable to obtain an object instance for the
java:comp/env/com.airline.controllers.FlightDetails/flightService
reference.
The exception message was: CWNEN1003E: The server was unable to find
the Web1/FlightService binding with the
com.airline.service.FlightService type for the
java:comp/env/com.airline.controllers.FlightDetails/flightService
reference.
FlightService.java
package com.airline.service;
import java.io.Serializable;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless
@LocalBean
public class FlightService implements Serializable {
public FlightService() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public Integer getNumOfSeats() {
return numOfSeats;
}
public void setNumOfSeats(Integer numOfSeats) {
this.numOfSeats = numOfSeats;
}
public String getAirplaneModel() {
return airplaneModel;
}
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";
}
------******FlightDetails.java*******-------------
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
response.setContentType("text/html");
try {
flightService = (FlightService)new InitialContext().lookup("java:comp/env/Web1/FlightService");
System.out.println(flightService);
}
catch(Exception ex){
ex.printStackTrace();
}
if(flightService !=null){
out.println(flightService.getAirplaneModel());
out.println(flightService.getFrom());
out.println(flightService.getTo());
}
}
--------********server.xml*********----------------
<jndiObjectFactory id="flightService"
className="com.airline.service.FlightService"/>
<jndiReferenceEntry jndiName="Web1/FlightService"
factoryRef="flightService"/>
<webApplication id="Web1" location="Web1-0.0.1-SNAPSHOT.war"
name="Web1"/>
<!-- <application context-root="Web1" type="war" id="Web1"
location="Web1-0.0.1-SNAPSHOT.war" name="Web1"/>-->
</server>
Any Help would be appreciated!