How to @autowire some bean into JsonSerializer?

后端 未结 3 1133
孤街浪徒
孤街浪徒 2020-12-08 07:22

I am using lazy loading with hibernate in my web app.

I would like to load some objects from the database at the parsing stage of the server response

3条回答
  •  悲&欢浪女
    2020-12-08 08:10

    Solution is SpringBeanAutowiringSupport if you are using Spring Framework 2.5+.

    public class DesignSerializer extends JsonSerializer {
    
        @Autowired
            IDesignService designService;
        }
    
        public DesignSerializer(){
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);    
        }
    
    ...
    
    }
    

    I Hope that help you

提交回复
热议问题