0

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:

  • Whether I need to add any library files? I already added springjars & springcorejars
  • I am getting errors in org.springframework.web.bind.annotation files.
  • If possible give a suitable tutorial for the restfull service using Spring Framework.

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...!!!

2 Answers 2

1

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 !

Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

I didn't find any pom.xml file. I am trying to execute the example from this [link] (pretechsol.com/2013/08/…) Please Check this example and suggest me..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.