我正在尝试将一些旧代码从 WebSphere 迁移到 Tomcat。旧代码使用 Spring 3.2,现在我将 JAR 升级到 5.2.2。但不知何故,对象值不会持续存在。
我的控制器类是:
@Controller
@Scope("session")
public class OperationController {
private GUIDataObject guiDO = null;
/**
* Constructor
*/
public OperationController() {
}
@RequestMapping(value="/readDataSource")
@ResponseBody
public String readDataSource() {
try {
String[] sources = guiDO.getDataSources();
.
.
.
Code to work on Array sources
.
.
.
return "ok";
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}
/**
* Set the data sources in the Data Storage Area - these are passed as a "parameter" map
* in the request.
* @param webRequest : WebRequest which parameter map can be pulled from
* @return "ok"
*/
@RequestMapping(value="/setDataSources")
@ResponseBody
public String setDataSources(WebRequest webRequest) {
guiDO.setDatasources(webRequest.getParameterMap());
return "ok";
}
.
.
.
Lots of other code.
.
.
.
}
并且值存储在对象中:
public class GUIDataObject {
private String service;
private String uniqueProcessId;
private String userId;
private String vendor;
// record the data sources to read from
private Map<String, String[]> dataSources = null;
public GUIDataObject(String service, String uniqueProcessId, String userId, String vendor) {
super();
this.service = service;
this.uniqueProcessId = uniqueProcessId;
this.userId = userId;
this.vendor = vendor;
}
public void setDatasources(Map<String, String[]> datasources) {
this.dataSources = datasources;
}
public String[] getDataSources() throws Exception {
if (this.dataSources == null) {
throw new Exception("No datasources have been set from the GUI");
}
if (!this.dataSources.containsKey("source")) {
throw new Exception("No datasources have been set from the GUI");
}
return this.dataSources.get("source");
}
.
.
.
Lots of methods.
.
.
.
}
现在我的问题是dataSources
地图设置得很好。但是在获取值时,它们返回空。它在第二个 if 块中出错,所以我至少可以说它不为空。对象中还有其他地图/字符串,但我无法确定它们是否正确设置,因为这是第一个被命中的方法,之后它会出错。我可以看到在构造函数中初始化的值被保留得很好。所以不能真的哪里出错了。
相同的代码在 WebSphere 和 Spring 3.2 上运行良好。现在我不确定是否需要任何新配置才能使其正常工作。由于 3.2 非常非常老。对此的任何帮助将不胜感激。