为什么会出现java.lang.IllegalStateException这个错误?

@RequestMapping(value = "/download", method = RequestMethod.GET, produces ="application/json" , consumes="application/json")

public String downloadProjectRequirementdetails(@RequestParam("StudID") int studID) throws JSONException, JsonProcessingException {     

        Map<String, Object> response = new HashMap<String, Object>();

        Map<String, Object> result = new HashMap<String, Object>();


        List<Student> list = new ArrayList<Student>();

    /*      int stat = (int) result.get("o_status");

        if( stat ==106)

                 {

        */

        result = studDao.downloadtestScnario(studID);

        json = mapper.writeValueAsString(result);   

        JSONObject jsonObj = new JSONObject(json);

        if (jsonObj.has("#result-set-1")) {

            JSONArray jsonArray = jsonObj.getJSONArray("#result-set-1");

            if (jsonArray.length() > 0) {

                for (int i = 0; i < jsonArray.length(); i++) {

                    JSONObject MainObj = jsonArray.getJSONObject(i);

                    Student testdetails = new Student();

                    testdetails.setStudID(MainObj.getInt("StudID"));

                    testdetails.setFirstName(MainObj.getString("FirstName"));

                    testdetails.setLastName(MainObj.getString("LastName"));

                    testdetails.setAddress(MainObj.getString("Address"));

                    testdetails.setMobileNo(MainObj.getInt("MobileNo"));

                    list.add(testdetails);


                }

                response.put("response", list);

                response.put("StatusCode", 200);

                response.put("Message", "Download Completed");

            }


        } else {

            response.put("StatusCode", 204);

            response.put("Message", "No data found!!!");

        }

                 //}


        json = mapper.writeValueAsString(response);

        return json;

        }   



慕沐林林
浏览 93回答 2
2回答

FFIVE

该错误表明您没有创建 bean。创建一个 xml bean 配置文件,然后为 downloadProjectRequirementdetails 方法所在的控制器创建 bean!

Smart猫小萌

此异常是由于 bean 问题造成的。您必须创建一个 xml bean 配置文件,然后为此控制器创建 bean。您还可能注意到其他一些事情:您正在提供侦听器 ContextLoaderListener<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>但您没有为 spring 配置文件提供 context-param 。就像 applicationContext.xml 您必须为您的配置提供以下代码片段<context-param>&nbsp; &nbsp; <param-name>contextConfigLocation</param-name>&nbsp; &nbsp; <param-value>applicationContext.xml</param-value></context-param>如果您提供基于java的spring配置,意味着您当时没有使用xml文件进行spring配置,您必须提供以下代码:<!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContextinstead of the default XmlWebApplicationContext --><context-param>&nbsp; &nbsp; <param-name>contextClass</param-name>&nbsp; &nbsp; <param-value>&nbsp; &nbsp; org.springframework.web.context.support.AnnotationConfigWebApplicationContext&nbsp; &nbsp; </param-value></context-param><!-- Configuration locations must consist of one or more comma- or space-delimitedfully-qualified @Configuration classes. Fully-qualified packages may alsobe specified for component-scanning --><context-param>&nbsp; &nbsp; <param-name>contextConfigLocation</param-name>&nbsp; &nbsp; <param-value>com.nirav.modi.config.SpringAppConfig</param-value></context-param>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java