Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9320981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:45:54+00:00 2026-06-19T03:45:54+00:00

I am trying to use @responseBody in the controller to return a object am

  • 0

I am trying to use @responseBody in the controller to return a object am i getting exception. I have jackson jar in the application still it says the following error ClassNotFoundException could not intiatiate

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

root cause 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0': Cannot create inner bean '(inner bean)' of type [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] while setting bean property 'messageConverters' with key [6]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.jackson.map.ObjectMapper 

root cause 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.jackson.map.ObjectMapper

This is my code—->

 import org.springframework.stereotype.Controller;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.SessionAttributes;
    import org.springframework.web.servlet.ModelAndView;

    import com.lol.laks.sample.beans.*;

    @Controller
    @SessionAttributes
    public class ContactsController {
      @RequestMapping(value = "/addContact", method = RequestMethod.POST,     produces="application/json")
        public @ResponseBody Contacts addContact(@ModelAttribute("contact") Contacts contact,BindingResult result) {

            System.out.println("First Name:" + contact.getFirstname() +
                        "Last Name:" + contact.getLastname());
            return contact;
        }

        @RequestMapping("/")
        public ModelAndView showContacts() {

            return new ModelAndView("contacts", "command", new Contacts());
        }
    }

This is the jsp–>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> (http://www.w3.org/TR/html4/loose.dtd%27%3E)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<body>
<form:form method="post" action="addContact">

<table>
<tr>
    <td><form:label path="firstname">First Name</form:label></td>
    <td><form:input path="firstname" /></td>
</tr>
<tr>
    <td><form:label path="lastname">Last Name</form:label></td>
    <td><form:input path="lastname" /></td>
</tr>
<tr>
    <td><form:label path="lastname">Email</form:label></td>
    <td><form:input path="email" /></td>
</tr>
<tr>
    <td><form:label path="telephone">Telephone</form:label></td>
    <td><form:input path="telephone" /></td>
</tr>
<tr>
    <td colspan="2">
        <input type="submit" value="Add Contact"/>
    </td>
</tr>
</table> 

</form:form>
</body>
</html> 

This is the 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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/context/spring-context-3.0.xsd%27%3E)

  <context:component-scan base-package="com.tcs.laks.sample" />

 <mvc:annotation-driven />
 <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="mediaTypes">
    <map>
      <entry key="html" value="text/html"/>
      <entry key="json" value="application/json"/>
    </map>
  </property>
  <property name="viewResolvers">
    <list>
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <!--  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
-->        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    </list>
  </property>
  <property name="defaultViews">
    <list>
      <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
        <property name="prefixJson" value="true"/>
      </bean>
    </list>
  </property>
</bean>   
</beans> 

This is the beans

import org.springframework.stereotype.Component;

@Component
public class Contacts {
        private String firstname;
        private String lastname;
        private String email;
        private String telephone;
        public String getFirstname() {
            return firstname;
        }
        public void setFirstname(String firstname) {
            this.firstname = firstname;
        }
        public String getLastname() {
            return lastname;
        }
        public void setLastname(String lastname) {
            this.lastname = lastname;
        }
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        public String getTelephone() {
            return telephone;
        }
        public void setTelephone(String telephone) {
            this.telephone = telephone;
        }
} 

Please Tell me why it is not able to instantiate the class though the proper jars are included when Spring 3 automatically converts the object to json?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:45:56+00:00Added an answer on June 19, 2026 at 3:45 am

    I found the answer Myself the main problem was with the servlet.xml file adding

    <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/> 
    

    did the work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I am trying use gem tire to search in my application. I have tables
I have been trying to use PHPUnit to test an application. I have it
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Hi I'm trying use a datepicker on a field I have. I'm trying to
I'm trying use struts2-jasperreports plugin but getting an error with the type result: Grave:
I have the following XML response I am trying to deserialize using XmlSerializer. When
I have been trying to use the same HttpClient instance throughout different activities, but
I'm trying to write this method in my controller: @ResponseBody @RequestMapping(value = {/getTeams}, method
As a newbie in ExtJS I'm trying to use it with Spring MVC Controller.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.