gpt4 book ai didi

spring - AspectJ:Autowired字段在Initbinder中为空

转载 作者:行者123 更新时间:2023-12-04 16:44:30 29 4
gpt4 key购买 nike

我只是像下面描述的那样实现了AspectJ:https://stackoverflow.com/a/10998044/2182503

此解决方案工作正常,直到我注意到@Autowired中的@InitBinder字段为null为止。这些字段在@InitBinder中仅是空的。

@Controller
public class EmployeeController {
@Autowired private GenericDaoImpl<Role, Integer> roleDao;
@Autowired private GenericDaoImpl<Employee, Integer> employeeDao;
@Autowired private EmployeeValidator employeeValidator;

@InitBinder
private void initBinder(WebDataBinder binder) {
// autowired fields are null
binder.setValidator(employeeValidator);
binder.registerCustomEditor(Set.class, "roles", new CustomCollectionEditor(Set.class) {
protected Object convertElement(Object element) {
if (element != null) {
Integer id = new Integer((String) element);
Role role = roleDao.findById(id);
return role;
}
return null;
}
});
}

@PreAuthorize("hasRole('MASTERDATA_VIEW')")
@RequestMapping(value = { "/employees" }, method = RequestMethod.GET)
public ModelAndView showEmployeeList() {
// dao not null
List<Employee> employees = employeeDao.findAll();
...
}

我无法理解为什么有时它们为空而某些文本为空。(在同一个类中)

最佳答案

@Initbinder必须声明为public

关于spring - AspectJ:Autowired字段在Initbinder中为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21626581/

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