Reputation: 31
am trying to create Rest API in spring integration like
@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
@Service("employeeSearchService")
public class EmployeeSearchService {
public String getEmployee(Message<?> inMessage){
return "From Spring Integration RestFul API";
}
In 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
<import resource="classpath:META-INF/spring/integration/applicationContext-http-int.xml"/>
<context:component-scan base-package="org.springframework.integration.samples.rest"/>
In 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. Only i need REST API. Any one can help me please.Thanks in advance. 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'
@Gary Russell,waiting for you response.
Upvotes: 0
Views: 1512
Reputation: 313
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.
In your servlet definition, put right path for your contentConfigLocation, same as you defined in the 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>
Upvotes: 1