0

My English is not good. Please understand..

//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);
    }

}

When Service inject into controller... I'd like to make downloadInfoFile variable dynamic depends on a request parameter.

2 Answers 2

1

I'd recommend that you create a factory class into which you can pass the path you wish.

Sign up to request clarification or add additional context in comments.

Comments

0

If it was I,I would do it as follow:

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

    public DownloadManageService() {
    }

    public void setDownloadFileAccessObj... 
}

public class DownloadManageController {
    private DownloadManageService downService;

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

    public void exec(){
        ...
        this.downService.setDownloadFileAccessObj(new FileAccessObjectImpl(...))
        ...
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.