亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么會出現java.lang.IllegalStateException這個錯誤?

為什么會出現java.lang.IllegalStateException這個錯誤?

慕沐林林 2023-09-27 16:57:19
@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;        }   
查看完整描述

2 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

該錯誤表明您沒有創建 bean。創建一個 xml bean 配置文件,然后為 downloadProjectRequirementdetails 方法所在的控制器創建 bean!


查看完整回答
反對 回復 2023-09-27
?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

此異常是由于 bean 問題造成的。您必須創建一個 xml bean 配置文件,然后為此控制器創建 bean。


您還可能注意到其他一些事情:您正在提供偵聽器 ContextLoaderListener


<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

但您沒有為 spring 配置文件提供 context-param 。就像 applicationContext.xml 您必須為您的配置提供以下代碼片段


<context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>applicationContext.xml</param-value>

</context-param>

如果您提供基于java的spring配置,意味著您當時沒有使用xml文件進行spring配置,您必須提供以下代碼:


<!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext

instead of the default XmlWebApplicationContext -->

<context-param>

    <param-name>contextClass</param-name>

    <param-value>

    org.springframework.web.context.support.AnnotationConfigWebApplicationContext

    </param-value>

</context-param>


<!-- Configuration locations must consist of one or more comma- or space-delimited

fully-qualified @Configuration classes. Fully-qualified packages may also

be specified for component-scanning -->

<context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>com.nirav.modi.config.SpringAppConfig</param-value>

</context-param>


查看完整回答
反對 回復 2023-09-27
  • 2 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號