JSONObject in Spring MVC - SEVERE Context initialization failed error

I'm getting an error when I try to instatiate JSONObject:

SEVERE: Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'budgetController' defined in file [C:\Users\yqb18196\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Budget\WEB-INF\classes\biz\martyn\budget\controller\BudgetController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [biz.martyn.budget.controller.BudgetController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/json/JSONException

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

...

Here is where the error is occuring:

public class ApiClient {

...

public void requestData() {

String str = "{}";

JSONObject obj = new JSONObject(str); // <-- error

// ...

}

}

It is called from a Spring MVC controller, if that matters:

@Controller

public class BudgetController {

public BudgetController() {

ApiClient apiClient = new ApiClient();

apiClient.requestData();

}

...

I've...

Read More »

By: StackOverFlow - Wednesday, 14 November

Related Posts