Autowired Repository is Null in Custom Constraint Validator

前端 未结 4 2079
无人共我
无人共我 2020-12-06 03:17

I have a Spring based webapp. I am using several repository classes with annotations @Repository, @Transactional in my Controllers. That part works fine.

I created a

4条回答
  •  清歌不尽
    2020-12-06 03:38

    No luck with LocalValidatorFactoryBean. I have done some hack to solve this problem.

    @Component
    public class ServiceUtils
    {
        private static ServiceUtils instance;
    
        @Autowired
        private ListableBeanFactory factory;
    
        @PostConstruct
        public void init()
        {
            instance = this;
        }
    
        public static ListableBeanFactory getFactory()
        {
            return instance.factory;
        }
    }
    

提交回复
热议问题