據我所知,我可以使用@Autowired在類中注入一個bean。注入特定的bean作爲函數參數與多個參數
現在我很好奇:: 我不想有@Autowired的私人屬性。 我在我的控制器中有一個函數,我想直接在函數中注入bean作爲參數。 我得到一個錯誤,說該文件和令牌不是豆。
是否有自動裝配或注入我需要的bean作爲參數的方法?
@Controller
public class SpinalToolboxWebController {
/*@Autowired
private FileOperationsService fileOperationsService;
@Autowired
private Comparator<String> comparator;
@Autowired
private ServerResponse serverResponse;
@Autowired
private SoftwareCommunicationService softwareCommunicationService;
@Autowired
private StringBuffer stringBuffer;
@Autowired
private UserEnvironmentService userEnvironmentService;*/
@Autowired
@RequestMapping(value="/upload", method = RequestMethod.POST, produces="application/json")
public @ResponseBody
ServerResponse handleUploadedFiles(@RequestParam(value = "file") MultipartFile file,
@RequestParam(value="token") String token,
SoftwareCommunicationService softwareCommunicationService,
FileOperationsService fileOperationsService,
ServerResponse serverResponse)throws IOException {
System.out.println("Passing throught upload controller");
if(!fileOperationsService.isUploadedFileExtensionAllowed(file.getOriginalFilename()))
{
serverResponse.setUndefinedResponse();
return serverResponse;
}
if(fileOperationsService.uploadFile(file, token)){
serverResponse.setResponse(file, softwareCommunicationService.generateRawAndHeader(file));
}
else{
serverResponse.setUndefinedResponse();
}
return serverResponse;
}
}
爲什麼你不想要字段? – 2014-12-04 23:07:51