I am trying to build a SpringMVC application and try to invoke a controller. it is giving me an error of java.io.FileNotFound Exception. Application is built with a RootContext value 'springmvc' and installed on Websphere 9
URL being invoked to hit controller -
http://localhost:9080/springmvc/logon
and this URL is giving a filenotFound for ' /logon.'
But, at the same time http://localhost:9080/springmvc/
gets tied with Controller and giving the output as 'Hello World'.
I am not sure on why /logon is not being recognized.
I have tried by keeping URL Pattern in web.xml as /springmvc/ or /springmvc/* but they all are not working. I have tried giving complete path in Controllers too.
Controller '''
` @Controller
public class AdminController{
@RequestMapping(value="/logon" , method = RequestMethod.GET)
@ResponseBody
public String config(){
system.out.println("Inside Config Method");
return "Hello World!";
} `
'''
Web.xml
`
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/springmvc/*</url-pattern>
</servlet-mapping> `
todo-servlet.xml -
` <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="springmvc.com.controller" />
<mvc:annotation-driven />
</beans>`
I expect http://localhost:9080/springmvc/logon
to return the response from AdminController class.
Kindly suggest what am i missing or what url-pattern shouuld i try?
Assuming that AdminController is on the springmvc.com.controller package. The problem I see is the url-pattern, In this case the logon is expected on the path: http://localhost:9080/springmvc/springmvc/logon
The first one (springmvc) is the context of the application, all points start on it. The second is inside your application.
You need to define / to get the expected result.