Spring basic usage 3 - related properties of beans in the Spring container

        Foreword: The Spring container is a super factory, and the beans in the Spring container are the products of the factory. Which products the Spring container can produce depends entirely on the configuration of the developer in the configuration file. This article introduces the attributes and functions that can be added when configuring beans, basically covering the general functions in development.

This article focuses on the following issues:

  • Basic definitions and properties of beans
  • Configure Bean dependencies

1. Basic definition and properties of Bean

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

    <bean id="pencil"       class="com.wj.chapter1.ioc.constructor.xml.Service.Pencil"></bean>
    <bean id="ballpointPen" class="com.wj.chapter1.ioc.constructor.xml.Service.BallpointPen"></bean>
</beans>

 

1.1 Configuration file root element <beans>

      The <beans../> element is the root element of the Spring configuration file, which can specify the following attributes:

  • default-lazy-init : Specifies the default lazy initialization behavior of all beans configured under the <beans../> element; (default false)
  • default-merge : Specifies the default merge behavior of all beans configured under the <beans../> element (inheriting parent bean properties); (default true)
  • default-autowire : Specifies the default autowiring behavior of all beans configured under the <beans../> element; (default no)
  • default-autowire-candidates : Specifies whether all beans configured under the <beans../> element are defaulted as candidate beans for autowiring;
  • default-init-method : Specify the default initialization method of all beans configured under the <beans../> element;
  • default-destroy-method : Specifies the default recovery method for all beans configured under this <beans../> element.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326254160&siteId=291194637