gpt4 book ai didi

java - Spring动态构造函数值

转载 作者:行者123 更新时间:2023-12-01 15:31:30 24 4
gpt4 key购买 nike

我的英语不好。请理解..

//This is my Spring-mvc-based Controller
@Controller

public class DownloadManageController {
private DownloadManageService downService;

@Autowired
public void setPackService(DownloadManageService downService) {
this.downService = downService;
}
}

//This is my Spring-Bean which should have a dynamic value of contructor
Component

public class DownloadManageService {
private Log log = LogFactory.getLog(DownloadManageService.class);
private FileAccessObject downloadFileAccessObj = null;

DownloadManageService(String downloadInfoFile) {
this.downloadFileAccessObj = new FileAccessObjectImpl(
"d:/dat/download/" + downloadInfoFile);
}

}

当服务注入(inject) Controller 时...我想让 downloadInfoFile 变量动态依赖于请求参数。

最佳答案

我建议您创建一个工厂类,您可以向其中传递您想要的路径。

关于java - Spring动态构造函数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9475386/

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