Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Spring is an Inversion of Control (IoC) container that utilizes Dependency Injection (a fancy way of just saying that Spring creates and hands the JAVA object objects you would use normally have had to create in your own code to you. ).

Example of Not Using Spring

As a brief example Here is a class that does not use Dependency Injection, it calls "new ArrayListSomeOtherClass()" directly in its constructor.

Code Block
public class Example {

    private SomeOtherClass myObject = null;

    public Example(){
        myObject = new SomeOtherClass();
    }
}

Example Using Spring

Here is an example of a better coding practice, where we give up the responsibility for the creation of the class and allow the IoC/DI container to be responsible for its creation.

...

This immediately opens the door for "SomeOtherClass" to be changed out with new/other subclasses of "SomeOtherClass".  In Spring, the injections definition "example.xml" file might look like this:

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<beans>

    <bean id="someObject" class="com.example.SomeOtherClass"/>

    <bean id="ny-example" class="com.example.Example">
        <constructor-arg ref="someObject"/>
    </bean>

</beans>

Where, when the ServiceManager is started, two beans are instantiated by Spring, and one is used in the constructor argument of the other.

The Path is Clear

This tutorial focuses on adoption of Spring as a best practice for many aspects of DSpace development, from Core Library definition and instantiation to Application Developer implementation of customizations and addons.

The simplest instantiation of a Spring Container might look like the following.

Code Block
ApplicationContext context = new ClassPathXmlApplicationContext(
        new String[] {"example.xml"});

Example myExample = applicationContext.getBean("my-example");

But its important to note that as a user of the DSpace Service Manager, this code is "action" is handled for you and encapsulated within the ServiceManager API.

Code Block
/* Instantiate the Utility Class */
Example = new DSpace().getSingletonService("my-example",Example.class);

The Case For Spring

This tutorial focuses on adoption of Spring as a best practice for many aspects of DSpace development, from Core Library definition and instantiation to Application Developer implementation of customizations and addons.

  • Spring focuses around providing a Spring focuses around providing a way to manage your business objects. (DSpace currently lacks this capability).
  • Spring is both comprehensive and modular. Spring has a layered architecture, you can choose to use just about any part of it in isolation.
  • It is easy to introduce Spring incrementally into existing projects. (The Latest DSpace WebMVC, REST and XMLUI development efforts already leverage Spring WebMVC in the application tier).
  • Spring is designed from the ground up to help you write code that's easy to test. Spring is an ideal framework for test driven projects. (DSpace has only just introduced a JUnit Test Suite, which does not leverage Spring in its solution. However, the DSpace Service Manager already delivers a testing suite leverages Spring to support testing configuration).
  • Spring is an increasingly important integration technology, its role recognized by several large vendors. By utilizing Spring, DSpace will be able to incrementally improve its architecture to be more robust, and more "enterprise grade".

...

The ServiceManager provides a developer API of service lookups and manages the overall lifecycle control for the DSpace Application. During this Lifecycle it also manages the configuration of services by During this Lifecycle it also manages the configuration of those services, either through providing those properties to the Spring Application Context injecting those properties directly into the defined classes, or by providing those properties directly in the  by allowing properties to be pushed into the services as they start up (mostly from the ConfigurationService).

...

  1. Spring Injection, when used properly, means we do not need reallyneed to make "lookup calls" to a central "ServiceManager" or "DSpace" object to acquire the service beans we our own code to work with.
  2. Fewer lookups mean less centralized dependencies
  3. Fewer Centralized Dependencies means fewer bottlenecks in source Code Dependency Management.
  4. Fewer Bottlenecks means greater modularity and encapsulation, less need to carry around all the source code when overriding and customizing "dspace".
  5. More use of binary distributions means greater ease in upgrading DSpace.

...

Code Block
public abstract class DSpaceAbstractKernelTest extends DSpaceAbstractTest {

    @BeforeClass
    public static void initKernel() {
        _initializeKernel();
        assertNotNull(kernelImpl);
        assertTrue(kernelImpl.isRunning());
        assertNotNull(kernel);
    }

    @AfterClass
    public static void destroyKernel() {
        _destroyKernel();
    }

    /**
     * Test method for {@link org.dspace.kernel.DSpaceKernelManager#getKernel()}.
     */
    @Test
    public void testKernelIsInitializedAndWorking() {
        assertNotNull(kernel);
        assertTrue(kernel.isRunning());
        DSpaceKernel k2 = new DSpaceKernelManager().getKernel();
        assertNotNull(k2);
        assertEquals(kernel, k2);
    }

}

...

Defining the SERVICE in SPRING
THE SERVICE MANAGER
THE SPRING CONFIGThe XMLUI OVERLAY
AspectS
Consectetuer arcu ipsum ornare pellentesque vehicula, in vehicula diam, ornare magna erat felis wisi a risus. Justo fermentum id.
THEME RESOURCES
Developing with DSpace

Architectural Introduction

Maven Archetype

Project Generation

Maven Module Wiring

Dependencies

Tiers

Persisitence

Business

Application

Tools

Maven

Jar Projects

 Dependencies

Inheritance

modularity

War Projects

overlays

modularity

Spring

ServiceManager

Core Services

ConfigurationService

Configuration via Spring vs. ConfigurationService

DatabaseService

Opening Doors to Persistence Frameworks

DAO Repositories

Defining, Replacing and Augmenting Storage

Whats a Service?

Defining and Replacing Business Services

Creating Your Own Services

Webapplications

XMLUI / Cocoon

JSPUI (WebMVC)

Example

Facebook Authentication for DSpace

Spring Security

OAuth 2.0 for Spring Security

Facebook Authentication

Implementation

Spring Security Authenticator

Authentication Service

Anchor
standalone
standalone

...