这里实际上我正在尝试访问基于 spring 的完整服务,我没有在 web.xml 中配置 DispatcherServlet,而是使用 ContxtLoaderListener 加载我的 spring 配置文件。
从我的日志中,我可以看到我的服务正在初始化,当我访问上述 url 时,ICallServlet 正在接收请求,因为它的 url 模式为“/*”(我无法修改)。
在这里我的问题是我无法访问我的服务,请求没有到达我的服务。不使用 DispatcherServlet 有什么方法可以调用我的休息服务,请有人帮我解决这个问题。
我有一个休息控制器:
package mypackage; @RestController @RequestMapping("/api/casaOnboarding") public class CasaOnboardingRestService { @ResponseBody @RequestMapping(value="/pwebXML", method=RequestMethod.POST, consumes={"application/json", "application/xml"}) public ResponseEntity pwebXML(@RequestBody OnboardingReq onboardingReq, HttpServletRequest request, HttpServletResponse response){ System.out.println("Request Reached"); ---- } }
Web.xml(无 Dispatcher Servlet)
<?xml version="1.0" encoding="UTF-8"?> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:controllerServiceContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>iCallUI</servlet-name> <servlet-class>com.ui.ICallServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>iCallUI</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
控制器服务上下文.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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"> <context:annotation-config /> <context:component-scan base-package="mypackage"/> <task:annotation-driven /> </beans>
日志文件
10:45:41,643 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 62) Creating shared instance of singleton bean 'casaOnboardingRestService' 10:45:41,643 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 62) Creating instance of bean 'casaOnboardingRestService' 10:45:41,643 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 62) Eagerly caching bean 'casaOnboardingRestService' to allow for resolving potential circular references 10:45:41,643 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (ServerService Thread Pool -- 62) Finished creating instance of bean 'casaOnboardingRestService'
网址: http://localhost:8080/icall-ui/api/casaOnboarding/pwebXML