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

标签 spring spring-mvc aspectj aspectj-maven-plugin spring-mvc-initbinders

我只是像下面描述的那样实现了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/

相关文章:

java - 自定义查询不适用于 Spring Data Neo4j 存储库中的界面投影

spring - 来自 mvc :resource override other mappings which defined with annotation 的处理程序映射

ajax - Spring MVC 与 ajax 文件上传和 MultipartFile

java - Spring 安全: Multiple HTTP Config not working

Spring:@PreAuthorize 是否优先于 @Cacheable?

aspectj - 警告 javax.* 类型没有被编织,因为未指定编织器选项 '-Xset:weaveJavaxPackages=true'

java - 使用 Java 将方法调用限制为每秒 1 次?

java - AspectJ @DeclareParents defaultImpl 代码在用作依赖项时不使用

Spring 3.1 配置文件 : how to set in Stackato Tomcat container

java - Spring 中对 List 或 Map 的响应主体