New features of Spring 3.0
Ø Spring Expression Language
Ø IoC enhancements/Java based bean metadata
Ø General-purpose type conversion system and field formatting system
Ø Object to XML mapping functionality (OXM) moved from Spring Web Services project
Ø Comprehensive REST support
Ø @MVC additions
Ø Declarative model validation
Ø Early support for Java EE 6
Ø Embedded database support
2.5.1 Core APIs updated for Java 5
Ø BeanFactory interface returns typed bean instances as far as possible:
T getBean(Class<T> requiredType)
T getBean(String name, Class<T> requiredType)
Map<String, T> getBeansOfType(Class<T> type)
Ø Spring's TaskExecutor interface now extends java.util.concurrent.Executor:
extended AsyncTaskExecutor supports standard Callables with Futures
Ø New Java 5 based converter API and SPI:
stateless ConversionService and Converters
superseding standard JDK PropertyEditors
Advantages of autowiring.
Ø It can significantly reduce the volume of configuration required.
Ø It can cause configuration to keep itself up to date as your objects evolve. For example, if you need to add an additional dependency to a class, that dependency can be satisfied automatically without the need to modify configuration. Thus there may be a strong case for autowiring during development, without ruling out the option of switching to explicit wiring when the code base becomes more stable.
Disadvantages of autowiring:
Ø Spring is careful to avoid guessing in case of ambiguity which might have unexpected results, the relationships between Spring-managed objects are no longer documented explicitly.
Ø Wiring information may not be available to tools that may generate documentation from a Spring container.
Bean scopes
Ø singleton
Ø prototype
Ø request
Ø session
Ø global-session- if not portlet based application it will act like session
Dependency check modes
Ø none- no dependency checking
Ø simple- To check look for primitive types and collections if not unsatisfieddependencyexception will be thrown
Ø objects- To check for objects if not unsatisfieddependencyexception will be thrown
Ø all- of all types primitive,objects,collection and so on.
<bean id="CustomerBean" class="com.mkyong.common.Customer" dependency-check="simple">
Creating our own Annotation based bean
Ø @Required - Helps to ensure the autowire object should be instantiated
empty interface should be declared with
Ø @Retention(RetentionPolicy.RUNTIME)
Ø @Target(ElementType.MEthod)
Ø @{empty interface name} on autowiring the element [ provide above the setter method]
Bean instantiation through class
Ø @Configuration - Provided for class that is to be configured as config file
Ø @Bean(name="ab") - Provided for autowired bean class [instead of giving in <bean > tag we can use it like this]
Ø AnnotationConfigApplicationContext(AppCofg.class) -
Helps to call the configuration class
Helps to call the configuration class
postconstructor preconstructor
Ø @PostConstruct
Ø @PreConstruct
Annotated to call and after the method in the class
Pre-Post callback methods
Ø int-method - called after the constructor & @postconstruct is called
Ø destroy-method - called after @preconstruct is called [ like finally block]
interfaces - intializingbean,disposablebean
Ø initializingbean- afterPropertySet method has to be implemented
Ø disposblebean - destroy method should be implemented
No comments:
Post a Comment