如何@autowire 一些 bean 到 JsonSerializer? [英] How to @autowire some bean into JsonSerializer?
问题描述
我在我的网络应用程序中使用延迟加载和休眠.
我想在服务器响应的解析阶段从数据库加载一些对象
<块引用>@Component公共类 DesignSerializer 扩展了 JsonSerializer<Design>{@自动连线IDesignService 设计服务;<-- 为空
}
这是完全可以理解的,因为 DesignSerializer
正在使用每个对象的new"运算符进行实例化.
我确定有一种方法可以在创建 bean 时将其注入该序列化程序,但我不知道如何操作.
你们能帮我或给我指明正确的方向吗.
解决方案是 SpringBeanAutowiringSupport 如果您使用的是 Spring Framework 2.5+.
public class DesignSerializer 扩展 JsonSerializer{@自动连线IDesignService 设计服务;}公共 DesignSerializer(){SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);}...}
希望对你有帮助
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
@Component public class DesignSerializer extends JsonSerializer<Design> { @Autowired IDesignService designService; <-- is null
}
Which is totally understandable because DesignSerializer
is being instantiated with the "new" operator for each object.
I am sure there is a way to inject my bean into that serializer when ever it is created, I just don't know how.
Can you guys help me or point me in the right direction.
Solution is SpringBeanAutowiringSupport if you are using Spring Framework 2.5+.
public class DesignSerializer extends JsonSerializer<Design> {
@Autowired
IDesignService designService;
}
public DesignSerializer(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
...
}
I Hope that help you
这篇关于如何@autowire 一些 bean 到 JsonSerializer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!