我在Spring @Scope(scopeName = WebApplicationContext.SCOPE_SESSION)中需要一些帮助。我正在创建Web应用程序,但会话对象有问题。我创建了课程:
@Component
@Scope(scopeName = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class FilterParameter {
private LinkedHashMap<String, String> filters;
public FilterParameter() {
filters = new LinkedHashMap<>();
}
public void addFilterParameter(String filterKey, String filterValue) {
if (filters.containsKey("byKeyword")) {
filters.remove("byKeyword");
}
filters.put(filterKey, filterValue);
}
public void addKeyWord(String filterValue) {
if (!filters.isEmpty()) {
filters.clear();
}
filters.put("byKeyword", filterValue);
}
public void removeFilterParameters(boolean allParam, String filterKey) {
if (allParam) {
filters.clear();
} else {
filters.remove(filterKey);
}
}
public LinkedHashMap<String, String> getFiltersList() {
return filters;
}
}
我将其实现为控制器之一中的一个字段。
@Controller
public class AssessmentController {
private FilterParameter filterA;
public AssessmentController(FilterParameter filterA){
this.filterA = filterA;
}
//...
}
我需要在另一个控制器中将其用作独立过滤器:
@Controller
public class ProcessController {
private FilterParameter filterB;
public ProcessController(FilterParameter filterB){
this.filterB = filterB;
}
//...
}
为两个控制器春季创建单例FilterParameter。如何设置它以创建FilterParameter的独立实例?