Why would it be beneficial to use stateless beans and dependancy injection over just a simple pojo with static methods? In other words, are the advantages to an EJB purely because of the underlying container benefits like threading, transactions, etc..?
Asked
Active
Viewed 736 times
2 Answers
2
A POJO with a bunch of static methods can't be easily mocked out for testing code that depends on it whereas a stateless singleton can.

digitaljoel
- 26,265
- 15
- 89
- 115
1
Yea, transactions mostly. The difference between a generic java bean and a SSB are pretty minor, but the big, common, visible values of the SSB are the transaction demarcation, and also the simple AOP listeners you can wrap around the methods if you want. You get quite a bit for a simple @Stateless annotation if you're already in an EJB container, but they do have their minor costs (that infrastructure isn't free) over a simple java bean.

Will Hartung
- 115,893
- 19
- 128
- 203