Reputation: 4029
I have a Spring 4.1.0 MVC project hosted inside a WildFly 10 server. and I am having trouble sending a request to without getting a 404. Here is my controller and one of the method declarations:
@Controller
@RequestMapping("/rest/message")
public class HomeController {
@RequestMapping(method = RequestMethod.POST, value = "/register")
public @ResponseBody PostResult register(HttpServletRequest request, @RequestHeader("userUid") String userUid,
@RequestHeader("Uid") String Uid, @RequestHeader(value = "firstName", required = false) String FirstName,
@RequestHeader(value = "lastName", required = false) String LastName,
@RequestHeader(value = "emailAddress", required = false) String EmailAddress,
@RequestHeader(value = "userName", required = false) String UserName,
@RequestHeader(value = "country", required = false) String Country,
@RequestHeader(value = "password", required = false, defaultValue = "") String Password,
@RequestHeader(value = "deviceId", required = false, defaultValue = "") String deviceID) {
}
}
I am using Postman to POST a request to http://localhost:8080/rest/message/register. I get back "404 - Not Found". I can successfully navigate to http://localhost:8080 to see the WildFly splash screen. I can also set a breakpoint in the Controller's constructor to see it constructed. In addition, I see the following in the server log leading me to believe the route has actually been registered:
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/rest/message/register],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.justPick5.jp5.returnObjects.PostResult com.justPick5.jp5.HomeController.register(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
To rule out the possibility of the parameters being the issue, here is a simple method in the controller:
@RequestMapping(method = RequestMethod.GET, value = "/testNoParams")
public @ResponseBody PostResult testNoParams() {
System.out.println("testNoParams");
return null;
}
Doing a GET from Postman to http://localhost:8080/rest/message/testNoParams has the same result.
Here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<!-- 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>
</web-app>
Any help appreciated.
Upvotes: 2
Views: 5027
Reputation: 13992
I had the same issue and fixed it by changing the Class annotation from @Controller
to @RestController
Upvotes: 1
Reputation: 46
I guess this issue is related to context path. http://localhost:8080/../rest/message/testNoParams
If I am not wrong you need to place the correct path over (/../), i.e. WAR has been deployed with some other name and may be you are hitting the incorrect path.
This often occurs with wildfly deployment.
e.g. : WAR deployed is ABC.1.0.0-BUILD-SNAPSHOT.war, but we often hit /ABC/ in our path.
So, please correct the context path. You can do this at wildfly -> deployment -> deployment Location.
Upvotes: 3