Reputation: 258
I'm currently trying to understand how the Dispatcher Servlet works with the Rest Controller ,but Postman returns 404 on everything I tried thus far.
The rest controller
@RestController
@RequestMapping(value = "/applications")
public class ApplicationController {
private static final Logger logger = LoggerFactory.getLogger(ApplicationController.class);
@Autowired
@Qualifier("ApplDAO")
private ApplDAO applDAO;
@Autowired
ApplicationService objServices;
@RequestMapping(value = "for_user\\{username:\\d+}", method = RequestMethod.GET)
public Application getApp(@PathVariable("username") String username){
Application app = applDAO.getByUsername(username);
return app;
}
}
My web.xml
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring4-servlet.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>springDispatcher</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>springDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I tried using url-pattern /* but with no results. This is the url I was trying to access http://localhost:8080/project/applications/for_user/username:acid Is there something wrong with the URL I'm using or have I used the dispatcher wrong. Here is the spring error
No mapping found for HTTP request with URI [/project/applications/for_user/username:acid
Upvotes: 0
Views: 1876
Reputation: 258
Answered by JB Nizet
Why do you use backslashes instead of slashes in your RequestMapping? Why do you use the regex \d+ if you want to send username:acid (or acid?) as user name. Just use value = "/for_user/{username}", and use http://localhost:8080/project/applications/for_user/acid.
Upvotes: 1