@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 в почтальоне, я получаю эту ошибку:
<!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> /TestSpringProject/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>
и тот же URL в затмении I выдает следующую ошибку:
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)