Discover spring bean configuration xml file, include the articles, news, trends, analysis and practical advice about spring bean configuration xml file on alibabacloud.com
1. Set the scope of the beanWhen you create a bean instance from a Spring IOC container, you can not only instantiate the bean, but also specify a specific scope for the bean, and Spring supports the following 5 scopes:1. Singleton: Single case mode. In the entire IOC contai
I. Configuring Beans with Annotations1.1 OverviewIn contrast to XML, configuring beans in an annotated manner is more concise and elegant, and fits well with the concept of MVC component development, and is a common use in development.1.2 Using annotations to identify components① Normal components:@Component: identify a component managed by the Spring IOC container② Persistence layer components:@Respository
I. knowledge points
When you configure beans in the Spring IoC container, you may have more than one bean that shares some common configurations, such as attributes and attributes in the
Spring allows you to extract common bean configurations to form a parent bean. The
Spring bean configuration method and dependency Injection Method
Bean configuration method: through the full class name (reflection), through the factory method (static factory method instance factory method), FactoryBean
Configure bean
/Property>
Note: At the beginning of bean configuration, note that the attribute value of name in property must be the same as the name member variable in the bean class.
From the above. XML document, we can know that the ID attribute is a unique identifier of a bean. Th
The last time we spoke briefly about Spring's IOC, Spring's IOC is powerful in that there is a series of maintenance classes that can maintain bean's different relationships, and such maintenance is based on a highly configurable spring configuration file. This is a combination of my use of spring's IOC to talk about my experience in use, of course, the content i
1. Named Bean Each bean has one or more identifiers. These identifiers must be unique within the container in which they are loaded. A bean often has and has only one identifier, but if more than one name is required, additional aliases can be considered. XML-based configuration
I. the bean parsing process in XMLScan the meta-inf belowThe spring.schemas Bean defines the corresponding XSD position, which can be assisted in the idea.)spring.handlers xmlns corresponding bean specific parser, will generally inherit namespacehandlersupport,Nshandler The following is the specific parsing process, and the result of the final return is the beand
The following is a typical spring configuration file (application-config.xml):
12345678
beans>beanid="orderService" class="com.acme.OrderService"/>constructor-argref="orderRepository"/>bean>beanid="orderRepository" class="com.acme.OrderRepository"/>constructor-arg ref="dataSource"/>
Spring uses dependency injection to obtain simple and effective testing capabilities. Spring beans, dependencies, and beans required by services are described in the configuration file. The configuration file is generally in
IOC and DI:IOC (Inversion of control): The idea is to reverse the direction of resource acquisition. The traditional resource lookup method requires that the component initiate a request lookup resource to the container. In response, the container returns resources in a timely manner.When the IOC is applied, it is the container that proactively pushes the resources to the components it manages, and what the component does is to choose an appropriate way to receive resources. This approach is als
* @SpringBootApplication the core annotations of spring boot * @Ena Bleconfigurationproperties activates the bean that binds the resource file, such as User.class here or more*/@RestController @springbootapplication@enableconfigurationproperties (User.class) Public classsecondemoapplication {/*** @Autowired Automatic injection, you need to declare an activated
", 300000)); Cars.put ("Ford", New Car ("Ford", 400000)); Public Car getcar (String brand) { cars.get (brand); +} Configuration file for the factory method:1XML version= "1.0" encoding= "UTF-8"?> 2Beansxmlns="Http://www.springframework.org/schema/beans"3Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"4xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.spring
Spring is a powerful Java application framework. It is widely used in Java applications and provides enterprise-level services for plain old Java objects (pojo. Spring uses the dependency injection mechanism to simplify work and improve testability. The configuration file (usually in
The purpose of this blog: ① summary of their own learning process, equivalent to study notes ② to share their own experience to everyone, learn from each other, communication, not commercialcontent inevitably appear problems, welcome to correct, exchange, discussion, you can leave a message, can also be contacted by the following ways. I Internet technology enthusiasts, Internet technology enthusiastsWeibo: Ivan is in 0221qq:951226918--------------------------------------------------------------
I. Overview of IOC diIOC (Inversion of Control): The idea is to reverse the direction of resource acquisition. The traditional resource lookup method requires the component to initiate a request to the container to find the resource, in response, the container returns the resource in a timely manner. When the IOC container is applied, it is the container that actively pushes the resource to the component it manages, and the component simply chooses an appropriate way to accept the resource. This
Spring Bean configuration defaults to Single instanceThe bean defaults to Singleton.If you do not want a singleton, the following configuration:Singleton is the configuration of this bean is a singleton, if not write, is the defau
3.6. Inheritance of bean definitions
The bean definition contains a large amount of configuration information, including container-related information (such as initialization methods, static factory method names, and so on), as well as constructor parameters and property values. A child bean definition is a
I. IOC container configuration 1. Some concepts(1)IOC container :Definition: A container that has dependencies between managing objects and managing objects.Role: The application does not need to create its own object, and the object is created and assembled by the IOC container. The beanfactory is the core of the IOC container.Process: The IOC container reads the configuration metadata based on the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.