The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

souter (1) [Avatar] Offline
#1
Hi, I'm finding the book well written and look forward to working my way through it.
One criticism I would have though is I think it oversells Spring and I have yet to find any mention of possible weaknesses.

By way of example, I created a Hibernate DAO as my first spring class. I went to test it using a junit test and discovered I had to dependency inject the class.
To my mind this is bad for 2 reasons: a) I don't need DI in a class whose sole purpose is to test a specific other class b) I need to know an objects implementation i.e. is Spring based (or indirectly uses) in order to know how to use it i.e. new or DI.

Would people not agree this is a weakness, and the book is somewhat Panglossian for not addressing this?
spring4j (2) [Avatar] Offline
#2
Re: Does Spring have any bad points?
Spring has no bad points
bbaron (61) [Avatar] Offline
#3
Re: Does Spring have any bad points?
For unit testing, Spring enables writing classes that are managed by Spring, without requiring Spring DI during testing. If you are testing a service layer class that depends on a dao for data access, it's pretty easy to instantiate the class under test directly and use a mock in place of the production dao (using JMock, Mockito or some other mock utility). Unit testing Hibernate DAOs is trickier, because you probably don't want to mock the Hibernate interfaces. So you can either use Spring to DI them or you can still instantiate everything directly if that makes more sense. The presence of Spring won't prevent that in most cases.

For integration testing, you will often find yourself using Spring to wire up dependencies. But the Spring container is lightweight enough that you can run through a fairly large set of these tests in 30 to 60 seconds. Besides, it's important to have JUnit tests to verify the correctness of the DI config. That saves you a lot of pain when it comes time to deploy the complete application, and not have to worry about DI configuration errors that could have been caught in the test phase of the build.
miss_duke (2) [Avatar] Offline
#4
Re: Does Spring have any bad points?
Spring has so many bad points

(1) The big thing may be, it is not stateful (Use CDI instead)
(2) Spring is not supporting the latest java CDI standard