1

I am learning Spring MVC but got an issue on my first application and I am not able to resolve it. I checked all articles available but still, I guess somewhere I am making some mistake.

Will you please able to help me to fix this?

Web.xml

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
  </context-param>

  <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/spring/dispatcher-servlet.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
  </servlet>


  <servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

Controller Class:

@Controller
public class HomeController
{
    @RequestMapping("/home")
    @ResponseBody
    public String goHome()
    {
        return "Welcome Home";
    }
}

is there something I am missing to configure? I know a very common issue but not getting the root cause.

I am using Eclipse Oxygen, Spring 4.3.14 and WebLogic

Error:

atcherServlet:508 - FrameworkServlet 'dispatcher': initialization completed in 791 ms 2018-02-24 12:37:22 WARN PageNotFound:1176 - No mapping found for HTTP request with URI [/springmvc-project] in DispatcherServlet with name 'dispatcher' <24 Feb, 2018, 12:37:28,882 PM IST> 2018-02-24 12:37:28 WARN PageNotFound:1176 - No mapping found for HTTP request with URI [/springmvc-project/] in DispatcherServlet with name 'dispatcher' <24 Feb, 2018, 12:37:38,883 PM IST> 2018-02-24 12:43:12 WARN PageNotFound:1176 - No mapping found for HTTP request with URI [/springmvc-project/home] in DispatcherServlet with name 'dispatcher' <24 Feb, 2018, 12:43:18,882 PM IST>

dispatcher xml

<mvc:annotation-driven />
<context:component-scan base-package="com.example.springmvc.controller" />
r-developer
  • 517
  • 1
  • 8
  • 21

1 Answers1

1

You are invoking incorrect URL. You must not include your project name if not specified otherwise in your web.xml. So you should try hitting your server with something like this http://localhost:8080/home. Also you should specify type of request i.e. GET/POST in RequestMapping annotation.