Currently I have the following web.xml
config:
<servlet>
<servlet-name>Website</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Website</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Server</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Server</servlet-name>
<url-pattern>/server/</url-pattern>
</servlet-mapping>
As for two example controllers:
@Controller
public class ApiRequests {
protected final Logger logger = Logger.getLogger(ApiRequests.class);
@RequestMapping(value = "api.json", produces = {"application/json"}, method = RequestMethod.GET)
@ResponseBody
public String handleActionJson(final HttpServletRequest request){
return "{test: 'blaat'}";
}
}
And
@Controller
@RequestMapping("/")
public class IndexController {
@RequestMapping("*.html")
public void showIndex(){
}
}
Now my problem is that when I try to call the /server/api.json url, the server won't give the json response, instead it gives me the following error:
PageNotFound:1108 - No mapping found for HTTP request with URI [/WorldDefense/server/api.json] in DispatcherServlet with name 'Website'
Which basically means its trying to search for /server/api.json in the Website servlet instead of the Server serlvet, as for my question: would it be possible to get this setup to work? (So /server/ to map to the Server servlet and all the other url combinations to the Website servlet)
Edit 1 I updated the code to reflect the changes as suggested by Costi Ciudatu but it still doesn't work. I removed the @RequestMapping("/server") and now only have the @RequestMapping at the handleActionJson method. Both resulting in these errors:
10:57:26,046 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/WorldDefense/server/server/api.json] in DispatcherServlet with name 'Website'
10:57:40,509 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/WorldDefense/server/api.json] in DispatcherServlet with name 'Website'
Mappings according to the tomcat log:
Server-servlet
11:03:49,655 INFO RequestMappingHandlerMapping:178 - Mapped "{[/api.json],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public java.lang.String com.world2.worlddefense.server.controllers.ApiRequests.handleActionJson(javax.servlet.http.HttpServletRequest)
11:03:50,125 INFO RequestMappingHandlerMapping:178 - Mapped "{[/api.json],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public java.lang.String com.world2.worlddefense.server.controllers.ApiRequests.handleActionJson(javax.servlet.http.HttpServletRequest)
Website-servlet
11:03:50,380 INFO RequestMappingHandlerMapping:178 - Mapped "{[//*.html],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.world2.worlddefense.website.controllers.IndexController.showIndex()
11:03:50,381 INFO RequestMappingHandlerMapping:178 - Mapped "{[/login],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.world2.worlddefense.website.controllers.TempTestController.showTest()