我正在使用Eclipse IDE运行我的Maven项目,该项目使用REST执行CRUD。该应用程序在Tomcat服务器上运行,但是当我转到http://localhost:8080/RESTfulCRUD/rest/employees/E01
时,出现上述错误。它说这些方法实际上是未定义的。这些类如下:
EmployeeService
@Path("employees")
public class EmployeeService {
// URI:
// /contextPath/servletPath/employees
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Employee> getEmployees_JSON() {
List<Employee> listOfCountries = EmployeeDAO.getAllEmployees();
return listOfCountries;
}
// URI:
// /contextPath/servletPath/employees/{empNo}
@GET
@Path("/{empNo}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Employee getEmployee(@PathParam("empNo") String empNo) {
return EmployeeDAO.getEmployee(empNo);
}
// URI:
// /contextPath/servletPath/employees
@POST
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Employee addEmployee(Employee emp) {
return EmployeeDAO.addEmployee(emp);
}
// URI:
// /contextPath/servletPath/employees
@PUT
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Employee updateEmployee(Employee emp) {
return EmployeeDAO.updateEmployee(emp);
}
@DELETE
@Path("/{empNo}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public void deleteEmployee(@PathParam("empNo") String empNo) {
EmployeeDAO.deleteEmployee(empNo);
}
}
EmployeeDAO
import org.o7planning.RESTfulCRUD.model.Employee;
public class EmployeeDAO {
private static final Map<String, Employee> empMap = new HashMap<String, Employee>();
static {
initEmps();
}
private static void initEmps() {
Employee emp1 = new Employee("E01", "Smith", "Clerk");
Employee emp2 = new Employee("E02", "Allen", "Salesman");
Employee emp3 = new Employee("E03", "Jones", "Manager");
empMap.put(emp1.getEmpNo(), emp1);
empMap.put(emp2.getEmpNo(), emp2);
empMap.put(emp3.getEmpNo(), emp3);
}
public static Employee getEmployee(String empNo) {
return empMap.get(empNo);
}
public static Employee addEmployee(Employee emp) {
empMap.put(emp.getEmpNo(), emp);
return emp;
}
public static Employee updateEmployee(Employee emp) {
empMap.put(emp.getEmpNo(), emp);
return emp;
}
public static void deleteEmployee(String empNo) {
empMap.remove(empNo);
}
public static List<Employee> getAllEmployees() {
Collection<Employee> c = empMap.values();
List<Employee> list = new ArrayList<Employee>();
list.addAll(c);
return list;
}
List<Employee> list;
}
再有一个Employee类,但是没有问题。关于这个问题有什么想法吗?