Spring Good Practices
These are some of the good practices while using spring framework.Spring IOC
- Select the factory carefully. If you are using basic IOC feature go for BeanFactory in place of ApplicationContext .
- Do not overuse the dependency injection. Spring is good for wiring configurations and services.
- Use type in constructor injection, as it removes ambiguities.
- Avoid wiring your domain model object. Another good parameter is if you are wiring too many objects with prototype scope rethink what you are using spring for. Spring is not a good place to keep your preferences and default value for objects to be populated.
- Divide your configuration details in different XML's This helps in maintainability. In web application we have two context already available, follow that paradigm. Put your spring security configuration in other XML's.
- Use good names for naming beans. Preferable use alias and wire the beans with interface name. e.g you have ExampleDao having implementation ExampleJDBCDao and ExampleHibernateDao. Register it like this:
<alias name="exampleHibernateDao" alias="exampleDao"> <bean id="exampleHibernateDao" class="ExampleHibernateDao."> <bean id="exampleJDBCDao" class="ExampleJDBCDao">
This helps in building indirection in XML. Program against interface bean names.
- Avoid autowiring, they reduce readability of code.
- Use dependency checking wherever it makes sense.
- Adopt annotations and Spring 2.5 (of course Javaa 5+ ) as soon as possible
Spring AOP
- Use AOP pointcut sensibly. Try to narrow down as far as possible. AOP has runtime performance implication as they introduce a level of indirection.
Spring Services
- Use caching of lookups through jndi if your jndi lookup is going to return the object which will not change in the lifetime of your program.
Spring Framework Index Java Home Home
Sidebar
Last wiki comments
- Introduction to ORM: ugg boots
- Introduction to ORM: ugg boots
- AOP: Thanks
- Lalit Bhatt: Superb Collection
- Lalit Bhatt: J2EE training
- Introduction to ORM: timberland shoes
- Introduction to ORM: jordan shoes
- Introduction to ORM: nike air max
- Pune Tourist Spots: KONARK PARK CLOSED
- jQuery Form Validations: Jquery Developer
Sidebar
Random Pages
- What markets work on?
- Why projects fail?
- Bharat Band - Jai ho
- The concept of Nation
- Don't hide complexity if it cannot be handled in a robustway
Last blog post comments
-
Prospective MLA for Pune election - 2009: ugg boots
Wed 01 of Sep., 2010 12:58 IST
-
Bharat Band - Jai ho: How do we protest?
Wed 18 of Aug., 2010 13:13 IST
-
Divided by Destiny: Contact
Fri 23 of July, 2010 16:02 IST
-
Future of Java: thesis writing
Sat 17 of July, 2010 01:50 IST
-
Hang till Death Mr. Kasab: some change
Mon 28 of June, 2010 16:03 IST
-
God Religion : Why we are confused?: Re: Is GOD Necessary?
Tue 15 of June, 2010 17:29 IST
-
God Religion : Why we are confused?: Is GOD Necessary?
Tue 15 of June, 2010 13:06 IST
-
The reason in religion: good
Wed 10 of Mar., 2010 18:30 IST
-
The confusion of Design Patterns: I think at macro level you are right...
Tue 23 of Feb., 2010 03:31 IST
-
The Indian Municipality: Comment
Fri 22 of Jan., 2010 13:20 IST
Post new comment