Spring 自动装配 bean 创建
我有一个 Spring/Vaadin 项目,我使用 RestTemplate 访问外部数据源,然后将其填充到 vaadin 组件中。 RestTemplate 自动连接到我的 EJB 中,并且这些 EJB 被注入到另一个 Spring 组件中。我如何控制 spring bean 何时创建?
例如:我有一个菜单结构,每个菜单条目都有一个 clickListener,它将正确的组件插入布局的内容部分。该组件是自动装配的,我可以在日志中看到它是在应用程序启动时创建的(因此调用 REST 服务),而不是在单击事件时创建。
另一个问题是,我所有正在自动装配的组件都不能具有对某些自动装配属性进行操作的构造函数(我得到 NullPointerException),因此,这些类甚至无法以通常的方式实例化。我能否以某种方式告诉 spring 在创建对象时首先自动装配字段,即以便构造函数方法可以使用元素?
I have a Spring/Vaadin project and I am using RestTemplate to access external datasources, which are then filled into the vaadin components. The RestTemplate is autowired into my EJBs and these EJBs are injected into another spring components. How can I control, when are the spring beans going to be created?
For example: I have a menu structure and each menu entry has a clickListener which inserts the right component into the content part of the layout. This component is autowired and I can see in the logs, that it is created(thus the REST service is called) at the application start, and not upon the click event.
Another issue is, that all my Components that are being autowired cannot have contructors which operate on some autowired properties (I get NullPointerException) and therefore, the classes cannot be even instantiated in a usuall way. Can I somehow tell spring to autowire the fields first upon the object creation, i.e. so that the constructor method can work with the elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@可配置
注释使由new
创建的对象成为Spring bean。 -- 需要方面 JThe
@Configurable
Annotation makes a object that is created bynew
a spring bean. -- Requires Aspect J