MicroStrategy ONE

Spring bean definitions

Spring configuration files consist of bean definitions. You customize authentication by creating custom definitions for the beans used for authorization and authenticaiton.

Here is an example of a simple bean definition in an XML configuration file:

Copy
<bean id="someBean" class="com.acme.package1.SomeBean" />

When Spring code sees this bean definition, it creates an instance of the com.acme.package1.SomeBean class and stores it in a bean repository called Spring Context keyed by the bean ID. Assigning IDs to beans allows those beans to be referenced in other bean definitions (see the examples below), and to be accessed from Java code (see the Spring documentation).

Bean definitions can contain constructor arguments:

Copy
<bean id="someBean" class="com.acme.package1.SomeBean">  
    <constructor-arg value="/auth/ui/loginPage"/>
</bean>

For this bean definition to work, the com.acme.package1.SomeBean class must have a constructor with one argument of type String. Otherwise, an exception will be thrown during application initialization.

Bean definitions can also have properties:

Copy
<bean id="someBean" class="com.acme.package1.SomeBean">
  <property name="prop1" value="/auth/ui/loginPage"/>
</bean>

For this bean definition to work the com.acme.package1.SomeBean class must have a public method setProp1(String value). Otherwise an exception will be thrown during application initialization.

Both constructor arguments and properties can refer to other beans. There are two ways of introducing beans in constructor arguments and properties—inline and "by reference".

  • Here is an example of introducing beans "inline":

    Copy
    <bean id="someBean" class="com.acme.package1.SomeBean">
      <constructor-arg>
        <bean class="com.acme.package1.AnotherBean">
      </constructor-arg>
    </bean>

    Notice that inline beans don't have IDs. They cannot be referenced from other beans.

  • Here is an example of introducing beans "by reference":

    Copy
    <bean id="someBean" class="co m.acme.package1.SomeBean">
      <property name="prop1" ref="anotherBean/>
    </bean>
    <bean id="anotherBean" class="com.acme.package1.AnotherBean">

    The main advantage of using this method is that the same bean can be referenced from several beans. It can also be used simply to flatten the definition XML or to allow overriding bean definitions.