gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:27:19 25 4
gpt4 key购买 nike

@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;
}

public Map<String, Object> downloadtestScnario(int studID) {
Map<String, Object> map = new HashMap<String, Object>();

try {
SqlParameterSource in = new MapSqlParameterSource()
.addValue("i_Stud_id", studID);

map = sp_DownloadStudDetails.execute(in);


} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
return map;
}

存储过程是

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_DownloadStudDetails`(
in i_StudID int(11),
out o_status int(11)
)
BEGIN

#select * from student;
select StudID,FirstName,LastName,MobileNo,Address from student where StudID = i_StudID;
set o_status =106;
END

当我点击http://localhost:8080/TestSpringProject/download?StudID=1时 在 postman 中我收到此错误:

<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> &#47;TestSpringProject&#47;download</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/9.0.26</h3></body></html>

并且在 eclipse 中使用相同的 URL,我给出以下错误:

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:177)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1035)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1011)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:961)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:583)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4730)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5396)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:187)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)

最佳答案

该错误表明您没有创建 bean。创建一个 xml bean 配置文件,然后为 downloadProjectRequirementdetails 方法所在的 Controller 创建 bean!您可以使用以下帖子作为指南。

https://medium.com/omarelgabrys-blog/spring-a-head-start-beans-configuration-part-2-4a8c239b070a

关于java - 为什么会出现java.lang.IllegalStateException这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58255443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com