接线的Spring bean通过注释和XML上下文 [英] Wiring Spring bean through annotations and xml context
问题描述
我已经得到了下面的Spring服务:
I've got the following Spring service:
@Service
public class Worker {
@Autowired
private MyExecutorService executor;
@Autowired
private IRun run;
private Integer startingPoint;
// Remainder omitted
}
现在我要加载的起点
通过的.properties
文件。
Now I want to load the startingPoint
through a .properties
file.
是否有可能通过接线注释和Spring的服务,同时XML上下文?
Is it possible to wire a Spring service through annotations and an xml context at the same time?
也许是这样的:
<bean id="worker" class="Worker">
<property name="startingPoint">
<value>${startingPoint}</value>
</property>
</bean>
起点
通过XML上下文文件有线,一切变得自动连接。
startingPoint
is wired through the xml context file, everything else gets auto-wired.
推荐答案
是的!这是最绝对有可能,它是,如果你不能得到解决使用XML的一点点走的好方法。只要留下您的所有注释字段指定,他们会得到注射自动神奇。
Yes! This is most definitely possible, and it's a good way to go if you can't get around using a little bit of XML. Just leave all your annotated fields unspecified, and they'll get injected auto-magically.
虽然仅仅是明确的,我相信,你必须为你的整型字段提供了一个二传手。 Spring并不想直接到达并通过XML描述符中设置多个领域。
Though just to be clear, I believe that you'll have to provide a setter for your Integer field. Spring doesn't want to reach in directly and set fields via the XML descriptor.
这篇关于接线的Spring bean通过注释和XML上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!