내 세상

[Spring] Spring Core 본문

Technical/Spring

[Spring] Spring Core

sga8 2019. 7. 30. 14:36
728x90
반응형

BeanFactory

-       The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object.

-       The BeanFactory provides the configuration framework and basic functionality.

 

ApplicationContext

-       ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring’s AOP features; message resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications.

-       ApplicationContext adds more enterprise-specific  functionality.

-       ApplicationContext is a complete superset of the BeanFactory dd

 

Beans

-       The objects that form the backbone of your application and that are managed by the Spring IoC container

-       A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

-       Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

 

Figure 1. The Spring IoC container

“These days many developers choose Java-based configuration for their Spring applications.”

 

For information about using other forms of metadata with the Spring container, see:

  • Annotation-based configuration: Spring 2.5 introduced support for annotation-based configuration metadata.
  • Java-based configuration: Starting with Spring 3.0, many features provided by the Spring JavaConfig project became part of the core Spring Framework. Thus you can define beans external to your application classes by using Java rather than XML files. To use these new features, see the @Configuration, @Bean, @Import and @DependsOn annotations.

 

 

References to other beans (collaborators)

Specifying the target bean through the parent attribute creates a reference to a bean that is in a parent container of the current container. The value of the parent attribute may be the same as either the id attribute of the target bean, or one of the values in the name attribute of the target bean, and the target bean must be in a parent container of the current one. You use this bean reference variant mainly when you have a hierarchy of containers and you want to wrap an existing bean in a parent container with a proxy that will have the same name as the parent bean.

<!-- in the parent context -->

<bean id="accountService" class="com.foo.SimpleAccountService">

    <!-- insert dependencies as required as here -->

</bean>

<!-- in the child (descendant) context -->

<bean id="accountService" <!-- bean name is the same as the parent bean -->

    class="org.springframework.aop.framework.ProxyFactoryBean">

    <property name="target">

        <ref parent="accountService"/>

         <!-- notice how we refer to the parent bean  -->

    </property>

    <!-- insert other configuration and dependencies as required here -->

</bean>

 

 

 

Collections

In the <list/>, <set/>, <map/>, and <props/> elements, you set the properties and arguments of the Java Collection types List, Set, Map, and Properties, respectively.

<bean id="moreComplexObject" class="example.ComplexObject">

    <!-- results in a setAdminEmails(java.util.Properties) call -->

    <property name="adminEmails">

        <props>

            <prop key="administrator">administrator@example.org</prop>

            <prop key="support">support@example.org</prop>

            <prop key="development">development@example.org</prop>

        </props>

    </property>

    <!-- results in a setSomeList(java.util.List) call -->

    <property name="someList">

        <list>

            <value>a list element followed by a reference</value>

            <ref bean="myDataSource" />

        </list>

    </property>

    <!-- results in a setSomeMap(java.util.Map) call -->

    <property name="someMap">

        <map>

            <entry key="an entry" value="just some string"/>

            <entry key ="a ref" value-ref="myDataSource"/>

        </map>

    </property>

    <!-- results in a setSomeSet(java.util.Set) call -->

    <property name="someSet">

        <set>

            <value>just some string</value>

            <ref bean="myDataSource" />

        </set>

    </property>

</bean>

 

 

728x90
반응형