Grace Huang
Grace Huang

Reputation: 5699

Limit on number of beans in Spring MVC

I am developing a web app using Spring MVC. I want to know whether there is a limit on the number of beans in an application context. If I have too many beans, would that be a problem when loading the app? Would it be a performance issue?

Upvotes: 1

Views: 4029

Answers (3)

Luke Cartner
Luke Cartner

Reputation: 306

The Bean creation block in doGetBean has multiple synchronised blocks that lock the bean creation. This means if you create a large number of prototype or request scoped beansyou will suffer from thread contention. Keep in mind this limit is only likely if it is a high volume application. However if it is a high volume application this will bring the system to its knees.

Upvotes: 0

Andrea Girardi
Andrea Girardi

Reputation: 4437

No there aren't. I suggest to split the beans in different application context and load only those you need. For my project, I put all camel configuration related on a context and all beans to inject database classes in one other.

With a single file with all beans, keep in mind that if should not so easy to maintains.

Try to take a look to that Splitting applicationContext to multiple files

Upvotes: 2

Pankaj Gadge
Pankaj Gadge

Reputation: 2814

Nopes, there is no limit as such on declaring beans in application context. The only thing you may want to take care is the dependency injection among different beans.

Its a general approach to differentiate beans based on their functioning and declare it in different context xml file. For example, you might want to declare JMS related beans in jms.xml file, that way you modularize your context related files and save the trouble of injecting many beans in one file.

Hope this helps

Upvotes: 0

Related Questions