In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Declare Bean
The root element of the Spring configuration file is.
Within the element, you can put all the Spring configuration information, including the declaration of the element.
In addition to the Beans namespace, the core framework of Spring comes with a total of 10 namespace configurations:
Namespace usage aop provides configuration elements for declaring aspects and @ AspectJ annotated class proxies for Spring aspects beans support declaring Bean and assembling Bean, is the core and most primitive namespace of Spring context provides configuration elements for configuring Spring application context, including automatic detection and assembly of Bean, injection of non-Spring directly managed objects jee provides integration with Java EE API For example, JNDI and EJBjms provide configuration elements for declarative message-driven POJO lang support the ability to configure Beanmvc implemented by Groovy, JRuby, BeanShell, etc. SpringMVC-enabled capabilities, such as annotation controller, view controller and interceptor oxm support Spring object to xml configuration mapping tx provides declarative transaction configuration util provides a variety of tool class elements, including configuring collections as Bean, supporting attribute placeholder elements
The structure of xml is as follows:
. .
Based on constructor injection
Use elements. If you do not configure the element, Spring will use the default constructor.
Create a Bean through the factory method
The element has a factory-method attribute that allows us to call a specified static method instead of the constructor to create an instance of a class.
Configure the scope of Bean
The element has a scope attribute, which allows us to specify the scope of Bean. There are several main scopes of Bean, and the default scope is singleton singleton.
Scope definition singleton in each Spring container, a Bean definition has only one object instance (the default) prototype allows the definition of Bean to be instantiated any time (one instance is created for each call) request in a HTTP request, each Bean definition corresponds to an instance. This scope is valid only in a Web-based Spring context, such as SpringMVC. Session in a HTTP Session, each Bean definition corresponds to an instance. This scope is valid only in a Web-based Spring context, such as SpringMVC. Global-session in a global HTTP Session, each Bean definition corresponds to an instance. This scope effectively configures the initialization and destruction methods of Bean only in the Portlet context
Spring provides a hook method for the Bean lifecycle.
To define initialization and destroy operations for Bean, you only need to use the init-method and destroy-method parameters to configure the elements. The init-method property specifies the method to be called when the Bean is initialized; the destroy-method property specifies the method to be called before the Bean is removed from the container.
Configure all common default initialization and destruction methods using the default-init-method and default-destroy-method attributes of the element
...
Properties of injected Bean
Use elements. Value populates the base type value, ref populates the reference
Assembly collection properties, Spring provides four types of collection configuration properties
POEM3 POEM2 POEM1
Assembly null value
In addition to element configuration attributes, you can also assemble attributes using spring's namespace p. Of course, you have to introduce the namespace p into the element first.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.