Spring的@Autowired是一个巨大的性能问题吗? [英] Is Spring's @Autowired a huge performance issue?

查看:825
本文介绍了Spring的@Autowired是一个巨大的性能问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目......我不知道... 200-300 daos / services / controllers我使用 @Autowired 连接所有内容而不是指定 applicationContext.xml 中的所有内容。

I have a project that has... I dunno... 200-300 daos/services/controllers and I use @Autowired to wire everything together rather than specify everything in the applicationContext.xml.

我的问题是,这对我的性能有多大影响启动时间?是否值得删除所有 @Autowired 注释并实际通过 applicationContext.xml ?

My question is, how much of a performance impact does this have on my startup times? Would it be worth it to remove all of the @Autowired annotations and actually wire this application up manually via the applicationContext.xml?

从架构的角度来看,我喜欢 @Autowired 。我不想通过使用xml文件添加另一层复杂性 - 就我而言,它没有增加任何价值。但是,如果这种事情为我的容器的加载时间增加10秒,我可能会考虑它。如果成本是100毫秒,那么我将保持原样。

From an architectural point of view, I like @Autowired. I don't want to add another layer of complexity by using the xml file - it adds no value as far as I am concerned. But if this sort of thing is adding 10 seconds to my container's load time, I may consider it. If the cost is 100 milliseconds, then I'll leave it as it is.

谢谢

推荐答案

几乎一样。组件扫描有点贵(当你扫描 @Service @Component )时,但正如你所说的那样,它是启动时间 - 它只发生一次。在中等机器上,即使使用注释,它也会很快启动。

Practically the same. Component scanning is a bit more expensive (when you scan for @Service, @Component), but, as you said, it is startup-time - it happens only once. And on a moderate machine it starts pretty quickly even with annotations.

一般来说,我不会放弃这种方法只是因为它增加了一些启动时间。而且我可以向你保证这一点并不重要(正在开展比你现在更大的项目)

Generally, I wouldn't abandon the approach just because it adds a bit of startup time. And I can assure you it is nothing significant (working on a bigger project than your right now)

这篇关于Spring的@Autowired是一个巨大的性能问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆