TDJSS
TDJSS

Reputation: 21

Spring Restful Services Example showing Error..!

I am new to spring restfull services. I know I made some mistakes in this. But I couldn't identify these. I don't know what should i do next. Please Suggest me to the following:

I have just added the Screen shoots and the code below:

StateController.java

package com.spring.restful;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/state")
public class StateController {
    @RequestMapping(value = "/{code}", method = RequestMethod.GET)
    public  @ResponseBody String getState(@PathVariable String code) {
        String result;
        if (code.equals("KL")) {
            result = "Kerala";
        } else {
            result = "Default State";
        }
        return result;
    }
}

dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <context:component-scan base-package="com.pretech" />
    <mvc:annotation-driven />
  </beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringRestFulExample</display-name>
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

Screen Shoot of the error page

Suggest Your Thoughts...!!!

Upvotes: 0

Views: 129

Answers (2)

M2hp
M2hp

Reputation: 205

Copy Spring libs into WEB-INF/lib -> select all libs -> right click -> Build Path -> Add to Build Path -> and it's done

you can download spring jars from this link -> link

There are different versions, you better download version 3 and later because they completely support spring Annotations based !

after your download got finished and you extract zip file, there may be 3 different jar files for each package Example spring core : (lib/bin, source, doc). you just need the lib/bin libs to copy into your WEB-INF/lib folder!

if you had any question, feel free to ask !

Upvotes: 1

deepakborania
deepakborania

Reputation: 166

Post your pom.xml too. I can't find it in your screenshot but you appear to be building with Maven. Did you add other required jars like spring-web etc?

Upvotes: 0

Related Questions