View RSS Feed

Spring Framework

SpringSource Spring Framework tutorials and examples. Focusing on Spring 3 and above.

  1. How to Write a BeanPostProcessing in Spring

    by , 11-16-2011 at 04:28 PM
    In the previous tip we talked about special beans in Spring. One of the Spring’s special beans that I had mentioned was using the BeanPostProcessor interface in order to cut into the bean’s life cycle and review or alter its configuration. In this tip, I will show you how to wire one. As mentioned in the previous tip I mentioned that the BeanPostProcessor provides two methods to alter the bean after it has been created and wired:

    Java Code:
    Object postProcessBeforeInitialization(Object bean,
    ...
  2. Spring's Special Beans

    by , 11-16-2011 at 04:25 PM
    The majority of beans in Spring are configured by the Spring container and made available for use in the application. Apart from these standard beans, Spring also has groups of beans that each serve a special purpose. The way in which Spring identifies these beans is because these beans have implemented certain interfaces that Spring considers special. The use of these interfaces allows these beans to do the following:
    • Post processing bean configuration in order to be involved in the bean
    ...
    Categories
    Bean , Configuration , XML
  3. How to Autowire a Spring Bean

    by , 11-16-2011 at 04:23 PM
    In previous tips, we have shown how to wire bean’s properties using the <property> element. There is an alternative approach that can be used. It’s called autowiring. In this approach, Spring will wire your beans automatically if you set the autowire property on each <bean> on each of the beans that you want to autowire. There are four types of autowiring that Spring uses:

    • byName—Spring will attempt to find a bean in the container whose name (or ID) is the same as the
    ...
  4. Wiring Sets, Maps and Properties in Spring

    by , 11-16-2011 at 04:19 PM
    Similarly to lists, there are times when you will need to map to other types of collections. In this tip, I will outline what you need to do to wire sets, maps and properties. The key to remember is that you want to wire your bean to the same type that is being used in the class definition. So if your bean has a java.util.Set property to guarantee uniqueness in the collection, you want to use the same definition in the xml definition.

    So for example, if you want to use a java.util.Set, ...
  5. Wiring Lists and Arrays in Spring Beans

    by , 11-16-2011 at 04:17 PM
    Often you will have situations where you will need to wire properties that are lists or arrays. If you are using Hibernate jointly with Spring, you will need to se this in order to provide the list of Hibernate mapping files. In order to do this, you will use the <list> element to wire the property in the wiring XML file for either an array property or a java.util.List property.

    For example, when you want to map Hibernate mapping files, you will wire a LocalSessionFactoryBean ...
    Categories
    Bean , Configuration
  6. Spring Inner Beans

    by , 11-16-2011 at 04:15 PM
    Rather than configure beans separately and allow for Spring’s DI container to manage the injection of these beans into other beans, another means of wiring bean references is to embed a <bean> element directly in the <property> element. For example, the carDao property of the carService bean can be wired as follows:

    Java Code:
    <bean id="carService" class="com.acme.springexample.service.CarServiceImpl">
    <property name="carDao">
    ...

    Updated 11-30-2011 at 11:51 AM by Spring Framework

    Categories
    Dependency Injection , Bean
  7. Understanding the Difference Between Singleton vs. Prototyping of Spring Beans

    by , 11-16-2011 at 04:13 PM
    When you configure a new Spring beanBy default, all Spring beans are singletons. When the container dispenses a bean, it will always give the exact same instance of the bean. But sometimes you want the application context to return a unique instance for each time you request a specific bean. In this case, you would want to do is to define a prototype bean. When you define a prototype means that you define a blueprint of the bean. Every subsequent bean for this requested bean will be based on this ...
  8. The Lifecycle of a Spring Bean

    by , 11-16-2011 at 04:11 PM
    In this tip, we will look at the lifecycle of a bean. The bean lifecycle for a Spring bean is somewhat complex. It is important to understand the life cycle of a Spring bean. Otherwise it will be difficult for you as a programmer to use Spring to its full abilities especially because you may want to take advantage of some of the opportunities that Spring offers to customize how a bean is created. The startup life cycle of a typical bean as it is loaded into a BeanFactory container is shown: ...
    Categories
    Bean
  9. Using View Helper in Spring MVC

    by , 11-16-2011 at 04:08 PM
    When you are looking to create the web front-end to your application, anyone with exposure to design patterns would apply the MVC pattern for this aspect of the application. There are a number of ways to do this, in Spring Framework, the means of accomplishing this is via an application controller and page controllers combined with a gateway servlet. This design resolves three important concerns of request processing:
    1. Request interception
    2. Invoking business components from page controllers
    3. Resolving
    ...
    Categories
    View Helper , MVC
  10. Listening for Events with Spring

    by , 11-16-2011 at 04:03 PM
    During the application life cycle, the ApplicationContext will publish a handful of events that tell interested listeners what’s going on. All of these events are all subclasses of the abstract class org.springframework.context.ApplicationEvent. A couple of these subclasses are:
    • ContextClosedEvent—Published when the application context is closed
    • ContextRefreshedEvent—Published when the application context is initialized or refreshed
    • RequestHandledEvent—Published within a web application
    ...
    Categories
    Event
  11. Working with Spring's Bean Factories

    by , 11-16-2011 at 12:18 PM
    BeanFactory serves as the core to Spring's Dependency Injection implementation. A BeanFactory is responsible for managing components and their dependencies. Bean is the term used in Spring to refer to any component managed by the container. Typically all Spring beans adhere, at some level, to the JavaBeans specification, although it is not required. The most obvious case of Spring deviating from the JavaBean specification is with the use of Constructor Injection to wire your beans together. ...
  12. Contextualized Dependency Lookup in Spring

    by , 11-16-2011 at 12:16 PM
    At its core, Inversion of Control (IoC), and therefore Dependency Injection (DI) offers a mechanism for provisioning component dependencies and managing these dependencies throughout their lifecycles. A component that requires certain dependencies is often referred to as the dependent object or, in the case of IoC, the target. Generally, IoC can be broken down into two subtypes: Dependency Injection and Dependency Lookup. With Dependency Lookup IoC, a component must obtain a reference to a dependency. ...
  13. Looking at Spring's Bean Factories

    by , 11-15-2011 at 02:17 PM
    BeanFactory serves as the core to Spring's Dependency Injection implementation. A BeanFactory is responsible for managing components and their dependencies. Bean is the term used in Spring to refer to any component managed by the container. Typically all Spring beans adhere, at some level, to the JavaBeans specification, although it is not required. The most obvious case of Spring deviating from the JavaBean specification is with the use of Constructor Injection to wire your beans together. ...
    Categories
    Uncategorized
  14. Looking at the Spring Application Context

    by , 11-15-2011 at 02:13 PM
    In order to take advantage of the full power of the Spring framework, you need to use Spring’s most advanced container, the application context. The ApplicationContext is similar to a BeanFactory. Both load bean definitions, wire beans together, and dispense beans upon request. But an ApplicationContext also does the following:
    • Application contexts provide a generic way to load other resources, such as images.
    • Application contexts can publish events to beans that are registered as listeners.
    • Application
    ...

    Updated 11-30-2011 at 11:46 AM by Spring Framework

    Categories
    Application Context
  15. Using Constructor Injection with Spring

    by , 11-15-2011 at 02:09 PM
    As we had mentioned in a previous tip, Inversion of Control (IoC) can be divided into two subtypes. There is Dependency Lookup which has two types, Contextualized Dependency Lookup and Dependency Pull); and Dependency Injection which also has two types, Constructor Injection and Setter Injection. In this tip we will look at Constructor Dependency Injection. Constructor Dependency Injection is Dependency Injection where a component's dependencies are provided to it in its constructor(s). The component ...

    Updated 11-30-2011 at 11:43 AM by Spring Framework

    Categories
    Dependency Injection
  16. Using Setter Injection in Spring

    by , 11-15-2011 at 02:02 PM
    An object is created in the Spring IOC container by invoking the zero-argument constructor. In this Setter Dependency Injection, the IoC container injects a component's dependencies into the component via JavaBean-style setter methods. A component's setters expose the set of the dependencies the IoC container can manage The dependent object is then passed as a parameter to the setter method. The CarService object needs data access objects (DAO) to execute data- base operations. The data access ...

    Updated 11-15-2011 at 02:10 PM by Spring Framework (Error in constructor for class)

    Categories
    Configuration , Dependency Injection , Bean
  17. The Core Features of the Spring Framework

    by , 11-15-2011 at 01:42 PM
    Dependency Injection
    In early tips, we discussed the issues around creating and initializing objects and it’s variables. Fortunately there is a way of addressing this situation in Spring that is a wonderful design pattern that they have applied to address this aspect. It is a combination of Inversion of Control and Dependency Injection. Many developers mistakenly believe that IOC and DI are the same thing. It is incorrect. IOC deals with inverting the control flow in an application, DI describes ...
Page 4 of 4 FirstFirst ... 234