Saturday, September 19, 2015

Benefits of Dependency Injection

This question is often asked at interviews, and a good list of reasons to use it can be found at http://anandmanisankar.com/posts/angularjs-dependency-injection-demystified/:
  • Separate the process of creation and consumption of dependencies
  • Let the consumer worry only about how to use the dependency, and leave the process of creation of the dependency to somebody else
  • Allow concurrent/independent development of the dependency and the dependent entity, while only maintaing a known contract
  • Facilitate changing of the dependencies when needed
  • Allow injecting mock objects as dependencies for testing, by maintaining the agreed contract

Saturday, September 12, 2015

Use of "Requires New" Transaction in Chunk Processing

One place to use @Transaction "requires new" is on the onXXXError listener methods (or on methods called from them) that fire on error events during chunk processing in Spring Batch because the current transaction might be rolled back (depending on any no-rollback-exceptions set):

With annotation based transaction handling you can put the annotation @Transactional(propagation=Propagation.REQUIRES_NEW) on the method to achieve this.
https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-2-restart-cursor-based-reading-and-listeners/