Relationship Between Spring beans and SpringBean
Relationship between beans: inheritance and dependency
Inherit bean configurations
- Spring allows inheritance of bean configurations. The inherited bean is called the parent bean, and the bean inherited from the parent bean is called the Child bean.
- Child beans inherit configurations from the parent bean, Including bean attribute Configuration
- Child beans can also overwrite the configurations inherited from the parent bean.
- The parent bean can be used as a configuration template or bean instance. If you only want to use the parent bean as a template, you can set the abstract attribute of <bean> to true, so that Spring will not instantiate this bean.
- Not all attributes in the <bean> element are inherited. For example, autowire and abstract
- You can also ignore the class attribute of the parent bean so that the child bean can specify its own class and share the same property configuration. However, the abstract must be set to true at this time.
Dependent bean Configuration
Spring allows you to use the depends-on attribute to set bean pre-dependent beans. The pre-dependent beans will be created before bean instantiation.
If the front-end is dependent on multiple beans, you can configure the bean name using commas and spaces.
Example:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <beans xmlns = "http://www.springframework.org/schema/beans" 3 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 4 xmlns: p = "http://www.springframework.org/schema/p" 5 xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 6 7 <! -- Abstract bean: bean whose abstract attribute is true. Such bean cannot be instantiated by IOC and can only be inherited. 8. If the class attribute of a bean is not specified, the bean must be an abstract bean 9 --> 10 <bean id = "address" 11 p: city = "BeiJing" p: street = "HuiLongGuan" abstract = "true"> </bean> 12 <! -- Bean configuration inheritance: Use the parent attribute of bean to specify which bean to inherit. --> 13 <bean id = "address2" class = "com. yl. autowire. address "parent =" address "> </bean> 14 15 <bean id =" address3 "class =" com. yl. autowire. address "16 parent =" address2 "p: street =" WuDaoKou "> </bean> 17 18 <bean id =" car "class =" com. yl. autowire. car "19 p: brand =" Audi "p: price =" 300000 "> </bean> 20 <! -- An associated car is required when configuring person! In other words, the bean "person" depends on the bean "car" --> 21 <bean id = "person" class = "com. yl. autowire. person "22 p: name =" Tom "p: address-ref =" address2 "depends-on =" car "> </bean> 23 </beans>
What is the relationship between JavaBean and Spring and Java?
Java is a general term for this technology.
JSP is only the view part. (*. Jsp part) Some labels are inserted into Java code to implement the business, but this method is not recommended.
JavaBean is the background business logic.
Spring is a framework. If your program is heavyweight and difficult to control, use Spring to manage transactions. Spring also provides componentized services, such as integrating Web, Hibernate, struts and other technologies.
Q: How is the framework integration relationship between struts 2 and Hibernate and Spring?
Thank you!
Let me clarify some ideas for you:
1. First of all, you need to understand that hibernate and struts are irrelevant, so there is no integration between them.
Some textbooks and reference books are actually nonsense, because:
A: As a central controller, struts must call some classes to complete some logic. In hibernate development, dao and service are often used to encapsulate it. Even jdbc is required. It is not a feature of hibernate at all. dao is used by struts actions, therefore, the service cannot be integrated with hibernate, so it is okay for them.
2. spring has many functions, for example, configuration. Let me just talk about bean management. In this case, he is a framework that can manage any java class. In this way, java classes of hibernate and struts functions can also be managed by them. That is to say, javabean, pojo, dao, service, action, factory, and util can all be managed by spring, create and destroy spring containers, but you can learn how to configure them yourself. Spring manages beans and generates their instances. Whether it is hibernate or struts, the method used is to add the jar package and write the applicationContent. xml file. In fact, the relationship between spring and hibernate struts is the same as that between common java classes. Configure them in xml format. However, spring provides more features, such as ioc, aop, and transaction management. Let's learn more.
3. struts is still a central control process. However, if their actions are configured or managed in spring, their instance generation is implemented by the spring container, therefore, struts remains unchanged. For struts2, he has changed a lot. In fact, the open-source framework of webwork has been modified, and the technical architecture has been separated from struts1.
4. Relationship between spring and hibernate. The key configurations of spring seem to be related to hibernate, such as javabean, service, and dao. However, the relationship between spring and hibernate is only one layer of configuration management, it has nothing to do with the business logic, generation, and data retrieval of hibernate. Hibernate does not change the ormapping of databases.
Hand-written. Give it to me. Thank you.