[英]Spring Integration Http rest service
am trying to create Rest API in spring integration like 我正在尝试在Spring集成中创建Rest API,例如
@ResponseBody
@RequestMapping(value="/employee", method=RequestMethod.GET,RequestMethod.POST},produces="application/json")
public String getData(){
return "From Spring Rest";
}
Below Are my file sample In Controller 以下是我在Controller中的文件示例
@Service("employeeSearchService")
public class EmployeeSearchService {
public String getEmployee(Message<?> inMessage){
return "From Spring Integration RestFul API";
}
In applicationContext-http-int.xml 在applicationContext-http-int.xml中
<int:annotation-config/>
<int:channel id="employeeSearchRequest" />
<int:channel id="employeeSearchResponse" />
<int-http:inbound-gateway id="inboundEmployeeSearchRequestGateway"
supported-methods="GET, POST" request-channel="employeeSearchRequest"
reply-channel="employeeSearchResponse"
mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
view-name="/employee" path="/services/employee"
reply-timeout="50000">
</int-http:inbound-gateway>
<int:service-activator id="employeeServiceActivator"
input-channel="employeeSearchRequest" output-channel="employeeSearchResponse"
ref="employeeSearchService" method="getEmployee"
requires-reply="true" send-timeout="60000">
</int:service-activator>
In web-application-config.xml 在web-application-config.xml中
<import resource="classpath:META-INF/spring/integration/applicationContext-http-int.xml"/>
<context:component-scan base-package="org.springframework.integration.samples.rest"/>
In Web.xml 在Web.xml中
<display-name>Spring Integration Rest HTTP Path Usage Demo</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- Spring application context declaration -->
/WEB-INF/config/web-application-config.xml
</param-value>
</context-param>
<servlet>
<servlet-name>Spring Integration Rest HTTP Path Usage</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring Integration Rest HTTP Path Usage</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
But am Getting below error.I have download this code sample from below URL and i removed some code. 但是我正在遇到错误。我已经从下面的URL下载了此代码示例,并删除了一些代码。 Only i need REST API.
只有我需要REST API。 Any one can help me please.Thanks in advance.
任何人都可以帮助我。谢谢。 https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/rest-http
https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/rest-http
No mapping found for HTTP request with URI [/services/employee] in DispatcherServlet with name 'Spring Integration Rest HTTP Path Usage' 在名称为“ Spring Integration Rest HTTP路径用法”的DispatcherServlet中未找到带有URI [/ services / employee]的HTTP请求的映射
@Gary Russell,waiting for you response. @Gary Russell,等待您的回复。
This problem generally happens when your sevlet is not reading your application context and hence is not building any binding between request path and your business logic. 当您的sevlet不读取您的应用程序上下文,因此没有在请求路径和业务逻辑之间建立任何绑定时,通常会发生此问题。
In your servlet definition, put right path for your contentConfigLocation, same as you defined in the context-param. 在servlet定义中,为contentConfigLocation设置正确的路径,与在context-param中定义的路径相同。 Something like this:
像这样:
<servlet>
<servlet-name>Spring Integration Rest HTTP Path Usage</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/web-application-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.