In my project using restful json, I have some files following as:
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<resources mapping="/images/**" location="/images/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.totoroads.webservice.android" />
</beans:beans>
My Jersey class:
@Path("/marker")
public class GetLatLongMapMarker {
@GET
@Path("/doMarker")
@Produces("application/json;charset=utf-8")
public String doMap() {
String carMaps = null;
ArrayList<CarMap> mapList = new ArrayList<CarMap>();
try {
mapList = DBConnection.getAllMapMarker();
Gson gson = new Gson();
carMaps = gson.toJson(mapList);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return carMaps;
}
}
When I want to get data from json by URL:
http://192.168.1.221:9999/restfulspringmvc/maker/doMarker
there is exception has happened, and this is log:
02:12:23.239 [http-bio-9999-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/restfulspringmvc/maker/doMarker]
02:12:23.239 [http-bio-9999-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /maker/doMarker
02:12:23.240 [http-bio-9999-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/maker/doMarker]
02:12:23.241 [http-bio-9999-exec-3] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/restfulspringmvc/maker/doMarker] in DispatcherServlet with name 'appServlet'
02:12:23.245 [http-bio-9999-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
How can I fix this configuration ? Thank you so much !!
答案 0 :(得分:0)
You are defining the request mappings in your jersey class this way:
@Path("/marker")
public class GetLatLongMapMarker {
@GET
@Path("/doMarker")
@Produces("application/json;charset=utf-8")
public String doMap() {
Which results in /[context-path]/marker/doMarker, but you are requesting this url http://192.168.1.221:9999/restfulspringmvc/maker/doMarker
.
So change maker
in your request to marker
and you should be able to reach it