for HTTP request with URI [/resteasy-jpa-crud/rest

2019-09-20 07:49发布

问题:

I have developed Spring + RestEasy + JPA example and trying to call the resful services through client like restclient and JSP, but I am unable to call it, not sure what is going wrong here. I've modified the code & placed here:: https://github.com/test512/resteasy-jpa-crud

Reference is taken from : http://middlewaremagic.com/jboss/?p=1185

javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/resteasy-jpa-crud/resteasy/services/employeeService/findall
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) ~[resteasy-jaxrs-3.0.8.Final.jar:na]
    at org.jboss.resteasy.springmvc.ResteasyHandlerMapping.getInvoker(ResteasyHandlerMapping.java:109) ~[resteasy-spring-3.0.8.Final.jar:na]
    at org.jboss.resteasy.springmvc.ResteasyHandlerMapping.getHandler(ResteasyHandlerMapping.java:85) ~[resteasy-spring-3.0.8.Final.jar:na]
    at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1123) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:934) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) [servlet-api.jar:na]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) [spring-webmvc-4.2.8.RELEASE.jar:4.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) [servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [catalina.jar:7.0.73]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.73]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat7-websocket.jar:7.0.73]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.73]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.73]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) [catalina.jar:7.0.73]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [catalina.jar:7.0.73]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [catalina.jar:7.0.73]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [catalina.jar:7.0.73]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:7.0.73]
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) [catalina.jar:7.0.73]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [catalina.jar:7.0.73]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) 

[catalina.jar:7.0.73]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) [tomcat-coyote.jar:7.0.73]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) [tomcat-coyote.jar:7.0.73]
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) [tomcat-coyote.jar:7.0.73]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-coyote.jar:7.0.73]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
2016-12-24 21:17:12 [http-bio-8080-exec-3] WARN  o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/resteasy-jpa-crud/resteasy/services/employeeService/findall] in DispatcherServlet with name 'springmvc-hibernate-resteasy'
2016-12-24 21:17:12 [http-bio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
2016-12-24 21:17:12 [http-bio-8080-exec-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'resteasy.spring.bean.processor'

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <display-name>resteasy-jpa-crud</display-name>

    <!-- Spring MVC Dispatcher Servlet -->
    <servlet>
        <servlet-name>springmvc-hibernate-resteasy</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc-hibernate-resteasy</servlet-name>
        <url-pattern>/resteasy/*</url-pattern>
    </servlet-mapping>

    <!-- loading Spring Context for registering beans with ApplicationContext -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springmvc-hibernate-resteasy-servlet.xml</param-value>
    </context-param>

    <!-- welcome file -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

database.properties:

mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/test
mysql.username=root
mysql.password=root
mysql.hibernate.dialect=org.hibernate.dialect.MySQLDialect
mysql.hibernate.hbm2ddl.auto=create
mysql.hibernate.show_sql=true

EmployeeController.java

@Path("/services/employeeService")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @POST
    @Path("/create")
    @Produces(MediaType.APPLICATION_XML)
    @Consumes("application/x-www-form-urlencoded")
    public Employee createEmployee(@FormParam("empno") Integer id, @FormParam("empname") String name) {
        Employee employee = employeeService.createEmployee(id, name);
        return employee;
    }

    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("/findall")
    public Collection<Employee> findAllEmployees() {
        Collection<Employee> collection = employeeService.findAllEmployees();
        return collection;
    }
}

EmployeeService.java

public interface EmployeeService {
    public void doAction();
    public Employee createEmployee(Integer id, String name);
    public void removeEmployee(Integer id);
    public Employee findEmployee(Integer id);
    public Collection<Employee> findAllEmployees() ;
}

EmployeeServiceImpl.java

public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeRepository employeeRepository;

    @Override
    public void doAction() {

    }

    @Override
    public Employee createEmployee(Integer id, String name) {
        Employee e = new Employee();
        e.setEmpno(id);
        e.setEname(name);

        employeeRepository.save(e);
        return e;
    }

    @Override
    public void removeEmployee(Integer id) {
        Employee e = employeeRepository.findByEmpno(id);
        if(e != null){
            employeeRepository.delete(id);
        }
    }

    @Override
    public Employee findEmployee(Integer id) {
        return employeeRepository.findByEmpno(id);
    }

    @Override
    public Collection<Employee> findAllEmployees() {
        return employeeRepository.findAll();
    }
}

When I am calling the http://localhost:8080/resteasy-jpa-crud/resteasy/services/employeeService/findall, I dont see service is getting called, please guide me.