[英]Json Webservice not found in Spring MVC Web App
我有一個Spring Web應用程序,該應用程序有兩個方面! 一個是Json Web服務,另一個是靜態視圖。 當我啟動Web應用程序並使用URL轉到視圖時,它可以正常工作。 但是,當我嘗試連接到Json Web服務時,服務器返回404錯誤。
這是我的dispatcher-servlet.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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">
<!-- SPECIFIC CONFIGURATIONS -->
<import resource="springConfigurations/common-config.xml"/>
<import resource="springConfigurations/mvc-config.xml"/>
<bean id="exceptionResolver" class="org.springframework.web.servlet.view.json.exception.JsonExceptionResolver">
<property name="exceptionView">
<value>jsonView</value>
</property>
<property name="errorHandler">
<list>
<ref bean="statusError" />
<ref bean="modelFlagError" />
</list>
</property>
<property name="exceptionHandler">
<list>
<ref bean="exceptionMessageExceptionHandler" />
<ref bean="stackTraceExceptionHandler" />
</list>
</property>
</bean>
<bean name="exceptionMessageExceptionHandler" class="org.springframework.web.servlet.view.json.exception.ExceptionMessageExceptionHandler" />
<bean name="stackTraceExceptionHandler" class="org.springframework.web.servlet.view.json.exception.StackTraceExceptionHandler"/>
<bean name="statusError" class="org.springframework.web.servlet.view.json.error.HttpStatusError" />
<bean name="modelFlagError" class="org.springframework.web.servlet.view.json.error.ModelFlagError" />
</beans>
這是common-config.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- COMMON CONFIGURATIONS -->
<mvc:annotation-driven/>
<tx:annotation-driven/>
<context:component-scan base-package="com.jkcs.touchpos.application.controller" />
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="location">
<value>/WEB-INF/views.xml</value>
</property>
<property name="order" value="0" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp">
<property name="order" value="1" />
</bean>
<!-- Annotations based Configuration -->
<context:annotation-config />
<!-- Components Auto-Detection (Backend) -->
<context:component-scan base-package="com.jkcs.touchpos" use-default-filters="false" >
<!-- Types annotated by Spring Managed, Controller and Transactional, or by an annotation that itself is
annotated by SpringManaged, Controller, Transactional -->
<context:include-filter type="annotation" expression="com.jkcs.touchpos.platform.annotations.SpringManaged"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.transaction.annotation.Transactional"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
</beans>
Views.xml文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>
</beans>
服務類。
@Controller
public class TouchPosService {
@RequestMapping(value = "/service", method = RequestMethod.GET)
public ModelAndView sampleJsonService(){
Map<String, String> model = new HashMap<String, String>();
model.put("Value", "Test Service to provide touchPos Data");
return new ModelAndView("jasonView", model);
}
}
我在這里做錯了! 我已經定義了兩個具有優先級的視圖解析器! 但是有些不起作用! 請在這件事上給予我幫助!
謝謝。
更新:
服務器啟動時,控制台將記錄以下內容。
2013-04-22 13:40:51.384:INFO::Logging to StdErrLog::DEBUG=false via org.eclipse.jetty.util.log.StdErrLog
log4j:WARN No appenders could be found for logger (com.jkcs.touchpos.server.jetty.ServerRunner).
log4j:WARN Please initialize the log4j system properly.
2013-04-22 13:40:51.384:INFO::jetty-7.0.0.v20091005
2013-04-22 13:40:51.947:INFO:/:Initializing Spring FrameworkServlet 'dispatcher'
2013-04-22 13:40:53.509:INFO::Started SelectChannelConnector@0.0.0.0:9157
然后從瀏覽器中拋出以下404!
您將視圖映射為jsonView <bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>
但稍后在控制器的return方法中,您將返回ModelAndView("jasonView", model);
這些都是一樣的嗎? 我可以看到您在這里返回的jsp文件名稱是否錯誤,這會導致404錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.