Spring is described
1. What is Spring?
Spring is an enterprise-level open source open development framework for Java. Spring is primarily used to develop Java applications, but some extensions are targeted at building Web applications on the J2EE platform. The Spring framework aims to simplify Java enterprise application development and promote good programming habits through a POJO-based programming model.
2. What are the advantages of using the Spring frame?
- Lightweight: Spring is lightweight, and the base version is about 2MB large.
- Control inversion: Spring implements loose decoupling through control inversion, so that partners give dependencies instead of creating or searching dependencies.
- Faceted programming (AOP) : Spring supports faceted programming and separates application logic from system services.
- Capacitors: The Spring package contains and manages the lifecycle and configuration of the object in use.
- MVC Framework: Spring’s WEB framework is a well-designed framework and a good alternative to WEB frameworks.
- Transaction Management: Spring provides a continuous transaction management interface that extends up to local and down to global transactions (JTA).
- Exception handling: Spring provides convenient apis for turning technology-specific exceptions (such as those thrown by JDBC, Hibernate, or JDO) into consistent, unchecked exceptions.
3. Which modules is Spring composed of?
Here are the basic modules of the Spring framework:
- Core module
- Bean module
- Context module
- Expression Language module
- JDBC module
- ORM module
- OXM module
- Java Messaging Service(JMS) module
- Transaction module
- Web module
- Web-Servlet module
- Web-Struts module
- Web-Portlet module
4. Core capacitor (should be used above and below) module.
This is the base of the Spring module for Spring frame base functions, BeanFactory is any spring-based should use the core. The Spring frame is built on top of this module, which makes Spring into a container.
5. BeanFactory – A BeanFactory example.
The Bean factory is an implementation of the factory model, providing the control inversion function, used to separate the required configurations and dependencies from the real application code. The most commonly used BeanFactory implementation is the XmlBeanFactory class.
6. XMLBeanFactory
The most commonly used is org. Springframework. Beans. Factory. XML. XmlBeanFactory, its root according to the loading beans defined in the XML file. The receptacle reads the data from the XML file and uses it to build a fully configured system or application.
7. Interpret AOP modules
AOP modules are used to deliver faceted development to our Spring applications, and much of the support is provided by the AOP consortium, which ensures the commonality of Spring and other AOP frameworks. This module guides the nativity data program into Spring.
8. Interpret JDBC abstraction and DAO modules.
By using JDBC image extraction and DAO module block, the simplicity of data library code can be guaranteed, and the problem caused by data library source error can be avoided. It provides a unified anomaly investigation layer on the error information of various data databases. It also leverages Spring’s AOP modules to provide transaction management services to objects in Spring applications.
9. Solve the antiimage/correlation projection into modular blocks.
Spring provides an object/relational mapping (ORM) tool on top of direct JDBC by providing ORM modules. Spring supports integration with mainstream ORM frameworks. Such as Hiberate,JDO and iBATIS SQL Maps. Spring’s transaction management also supports all of the above ORM frameworks and JDBC.
10. Decode WEB modules.
Spring’s WEB module is built on the Application Context module to provide a context suitable for WEB applications. This module also includes support for various aspects of the Web, such as explicitly handling multiple text upload requests and sequence level request parameter binding to your business object. It also has support for Jakarta Struts.
12. Spring with documents
The Spring package is an XML package that contains class information describing how to configure them and how to call each other.
13. What is a Spring IOC container?
Spring IOC is responsible for creating and managing objects (through dependent injection (DI), installing objects, configuring objects, and managing the entire life cycle of these objects.
14. What are the advantages of IOC?
IOC or dependent injection minimizes the amount of code to be used. It makes it easy for users to test, without the need for singletons and JNDI lookups. The minimum substitution and minimum intrusion make the coupling of loose and loose possible. IOC containers support hungry start-up and lazy loading services.
15. What is the common implementation of ApplicationContext?
- FileSystemXmlApplicationContext: this container loading beans from an XML file, the definition of XML Bean file of the full path name must be provided to the constructor.
- ClassPathXmlApplicationContext: This host also loads beans from an XML file. In this case, you need to set the classpath precisely because the host will find the bean configuration in the classpath.
- WebXmlApplicationContext: This container loads an XML file that defines an existing bean that the WEB should use.
16. What is the difference between Bean factory and Application Contexts?
Application Contexts Can provide one way to eliminate. one common way to do this is to add context sources (for example, contexts), They can send events to a bean that acts as a listener to the register. In addition, those operations performed on the objects in the container or container are not handled by the bean factory in a procedural formula, Can be managed in the declared formula in Application Contexts. Application Contexts supports MessageSource interface. The implementation of this interface provides a way to obtain local energy in a pluggable format.
17. What does a Spring look like?
- A joint that defines some work.
- This implementation includes the property, its setters, getters, functions, etc.
- Spring AOP The Spring XML configuration file
- Enable the client program to use the upper power
Dependency injection
18. What are Spring dependencies?
Dependency, a facet of IOC, is a general concept that can be interpreted in many ways. The idea is that you don’t use the creation object, but only describe how it was created. You do not directly assemble your components and services in the code, but specify which components require which services in the package, and the latter IOC host is responsible for assembling them.
19. What are the different IOC methods?
- The constructor depends on the constructor of a class, which has a list of parameters, each of which represents a dependency on other classes.
- Setter method notes: Setter method injection is a Setter method that the container calls after instantiating the bean with a parameterless constructor or static factory method. This implements setter-based dependent injection.
20. Which dependent injection method do you recommend to use, constructor injection or Setter injection?
You can use either of the dependent methods, the constructor method or the Setter method. The best solution is to enforce the dependency with constructor parameter implementation and the optional dependency with setter method implementation.
Spring Beans
What are Spring beans?
Spring Beans are Java objects that form the backbone of what Spring should use. They were initiated, installed, and managed by the Spring IOC container. These beans are created using the nativity data configured in the capacitor. For example, use the form of <bean/> in the XML text. Beans defined by the Spring framework are singleton Beans. There is a genus “singleton” in the bean tag; if it is set to TRUE, the bean is a singleton; otherwise, it is a prototype bean. Implicitly TRUE, so all beans missing in the Spring frame are singleton.
22. What does a Spring Bean bundle contain?
The semantics of a Spring Bean contain all the configuration metadata that the host must know, including how to create a Bean, its lifecycle details, and its dependencies.
23. How to provide the configuration element data for Spring capacitor?
There are three key methods to provide provisioning metadata for Spring receptors. XML configuration file. Collocation based on injection solution. Java-based provisioning.
24. How do you define the domain of thesaurus?
When defining a <bean> in Spring, we can also declare a utility domain for that bean. It can be defined through the scope genus in bean definition. For example, when Spring produces a new bean instance every time it is needed, the scope genus of the bean is specified as prototype. On the other hand, a bean must return to the same instance every time it is used, and the scope of this bean must be set to singleton.
25. Explain the scope of several beans supported by Spring.
The Spring frame supports the following five types of bean use domains:
- ** Singleton: ** Beans have only one instance per Spring IOC container.
- Prototype: A bean definition can have multiple instances.
- Request: Each HTTP request creates a bean that is only valid in the case of the Web-based Spring ApplicationContext.
- Session: In an HTTP session, there is one instance for each bean definition. This action domain is only valid in the case of web-based Spring ApplicationContext.
- Global-session: In an all-office HTTP session, a bean definition corresponds to an instance. This action domain is only valid in the case of web-based Spring ApplicationContext. The utility domain for the missing Spring bean is the Singleton.
26. Are the singleton beans in the Spring frame line-safe?
No, the singleton bean in the Spring frame is not line-safe.
27. Explain the lifecycle of beans in the Spring framework.
- The Spring facilitator reads the definition of the bean from the XML text and instantiates the bean.
- Spring populates all properties according to the bean’s definition.
- If the bean implements the BeanNameAware interface, Spring passes the bean’s ID to the setBeanName method.
- If the Bean implements the BeanFactoryAware interface, Spring passes the BeanFactory method to the setBeanFactory method.
- If you have any that is associated with the bean BeanPostProcessors, Spring will be postProcesserBeforeInitialization () method call them inside.
- If the bean implements the IntializingBean, call its afterPropertySet method. If the bean declares the initialization method, call the initialization method.
- If there are BeanPostProcessors and bean close union, this some bean postProcessAfterInitialization () method will be invoked.
- If the bean is real to DisposableBean, it will call destroy().
28. Which are the key bean lifecycle methods? Can you reload them?
There are two preferred bean lifecycle methods, the first being setup, which is called when the container loads the bean. The second method is called teardown, which is called when the container is unloading the class. The bean label has two override properties (init-method and destroy-method). With this you can use your own initiation and cancellation methods. They also have corresponding annotations (@postconstruct and @predestroy).
29. What is Spring’s inner bean?
When a bean is used only as a property of another bean, it can be declared as an inner bean, defined as an inner bean, in Spring’s XML-based ligand data, The <bean/> primitive can be used inside a <property/> or <constructor-arg/> primitive. The inner bean is usually nameless and its Scope is prototype.
30. How do I inject a Java aggregation in Spring?
Spring provides configuration elements for several collections:
- The
-
class is used to insert a list of values, allowing identical values.
- The
class is used to insert a set of values. Identical values are not allowed.
- The
-
Class for injecting a set of key-value pairs. The keys and values can only be strings.
31. What is bean installation?
Assembly, or bean assembly, refers to grouping beans together in the Spring container. The former is that the container needs to know the dependent relationship of the bean. How to put them together by relying on injection.
32. What is the automatic assembly of beans?
Spring capacitors can automatically assemble and configure beans that interact with each other, which means that the capacitors do not need <constructor-arg> and <property> configurations, Can manage the cooperation between beans through Bean factory automation.
33. Interpretation of automatic assembly of different formulas.
There are five kinds of automatic assembly formulations, which can be used to guide Spring capacitors to operate with automatic assembly formulations.
- No: The implicit formula is not automatic assembly, by explicitly setting the ref attribute to the assembly.
- ByName: By auto-assembly of parameter names, the Spring generator finds that the autowire property of the bean is set to BYName in the configuration file. The last container tries to match and install a bean with the same name as the bean’s property.
- ByType: : Through the auto-assembly of the parameter class, the Spring generator finds that the autowire attribute of the bean is set to byType in the configuration file. The last container tries to have a bean of the same type as the property of the bean. If there are more than one bean matching bar, an error is thrown.
- Constructor: This constructor class is similar to byType but supplies constructor parameters. If there is no defined constructor parameter type with parameters, an exception will be thrown.
- Autodetect: First try using Constructor for auto-assembly, and if that doesn’t work, use byType.
34. What are the limitations of automatic assembly?
The local limitation of automatic assembly is:
- Rewrites: You still need to use
andconfigurations to define dependencies, meaning always rewrites the auto-assembly. - Base data types: you cannot automatically configure simple properties, such as base data types, strings, and classes.
- Characteristics of mold paste: automatic assembly is not as accurate as explicit assembly, if possible, it is suggested to use explicit assembly.
35. Can you inject a NULL and an empty string in Spring?
You can.
The Spring injection solution
36. What is The Java-based Spring annotation configuration? Give some examples of solutions.
Java-based provisioning allows you to implement most of your Spring provisioning with the help of fewer Java annotations rather than through XML files. The @Configuration annotation, for example, is used to mark a class as a definition of a bean and is used by the Spring IOC container. Another example is @bean annotation, which shows that this method will return an object that should be logged into Spring as a Bean.
37. What is the receptacle configuration based on injection solution?
In contrast to XML documents, annotation type configuration depends on the assembly of components via byte code metadata rather than the pronunciation of brackets. Instead of describing bean configurations in XML, the developer implements configurations directly into the component class by annotating corresponding classes, methods, or properties.
38. How to open and disassemble?
In order to use annotation assembly, we must configure the <context:annotation-config/> element in the Spring configuration file.
39. @ the Required injection solution
This annotation indicates that the bean’s ownership must be set at the time of collocation, either through an explicit ownership value of a bean’s definition or through an automatic assembly, If @ Required annotations bean attribute is not set, the container will be thrown out BeanInitializationException.
40. The @autowired annotation
@autowired notes to provide more granular control, including where and how to complete the automatic assembly. It is used in the same way as @required to modify setter methods, constructs, and PN methods that have an arbitrary name and/or multiple parameters.
41. @ the Qualifier injection solution
@qualifier and @autowire are merged to eliminate confusion when there are multiple beans of the same class but only one of them needs to be auto-installed. Refers to the exact bean that needs to be installed.
Spring data asked
42. How to use JDBC more efficiently in the Spring frame?
Make use of SpringJDBC frame, resource management and error management will be reduced pricing. The developer only needs to write statements and queries to retrieve data from the data. JDBC can also be used more efficiently with the help of template classes provided by the Spring frame. This template is called JdbcTemplate (see here for examples)
43. JdbcTemplate
The JdbcTemplate class provides a number of convenient solutions, such as converting database data into base data classes or objects, implementing written or adjustable database operations as sentences, To provide for the self – defined meaning of the number of errors and errors.
44. Spring support for DAOs
Spring’s support for data Access Objects (DAOs) is designed to simplify its use with data access technologies such as JDBC, Hibernate, or JDO. This makes it possible for us to make a long cut. Coding also captures the unique anomalies of each technique without worrying about them.
45. What methods can Spring use to query Hibernate?
There are two ways to approach Hibernate in Spring:
- Control reverse Hibernate Template and Callback.
- The successor hibernateda support provides an AOP interceptor.
46. ORM supported by Spring
Spring supports the following ORMS:
- Hibernate iBatis
- JPA (Java Persistence API)
- TopLink JDO (Java Data Objects)
- OJB
47. How to combine Spring and Hibernate with Hibernateda Support?
Call LocalSessionFactory with Spring’s SessionFactory. The integration process is divided into three steps:
- Configure the Hibernate SessionFactory.
- The descendant hibernateda Support implements a DAO.
- Assemble in an AOP supported transaction.
48. Transaction management types supported by Spring
Spring supports two types of transaction management:
- Programmatic management: this means that your programmatic management brings you great vitality, but it is difficult to maintain.
- Explicit business management: this means that you can separate business code from business management, and you only need to use annotation and XML configuration for business management.
49. What are the advantages of the service management of the Spring frame?
- It provides an immutable programming model for different business apis such as JTA, JDBC, Hibernate, JPA and JDO.
- It provides a simple set of apis for programmatic job management rather than a bunch of miscellaneous job apis
- It supports explicit business management.
- It integrates well with Spring’s various data access abstraction layers.
50. What kind of business manager do you prefer?
Most Spring frame users choose the sound type of service management, because it has the least impact on the code should be used, so it is more consistent with the idea of a non-intrusion light weight container. Explicit business management is better than programmatic business management, though it is a little less dynamic than programmatic business management, which allows you to control things through code.
Spring aspect tangent programming (AOP)
51. The explanation of AOP
Faceted faceted programming, or AOP, is a programming technique that allows process modeling to block out cross-cutting points, or cross-cutting typical responsibility partitioning, such as logging and job management.
52. The cut surface Aspect
The AOP core is the cutting surface, encapsulating the common lines of multiple classes into reusable modules with a set of apis that provide cross-cutting power. For example, an astronomical module can be cut with an AOP facet called astronomical. Depending on the requirements, a process can have as many cut surfaces. In Spring AOP, facets are implemented through classes with @Aspect annotation solutions.
52. What is the difference between annotation points and crosscutting annotation in Spring AOP?
A key point is the action of a module, and a key point can be defined as a function we want to realize. Crosscut switch point is a switch point, this switch point is the whole should be used, and affect the whole should be used, such as the sun, security and data transmission, The amount of work required for each module to be used. Because of this, these are the cross cut points.
54. The connection point
The connection point represents a bit of an application in which we can plug an AOP facet, which is actually a bit that should implement Spring AOP using the application.
55. General knowledge
Knowledge is an action to be done before or after a method is executed, in fact, it is a code segment that the process is executed through the SpringAOP frame. Spring section can be used in five classes of general knowledge:
- Before: used before a method is executed.
- **after: **after the implementation of the method to use the general knowledge, there is no discussion on the implementation of the method is successful.
- ** AFTER-returning: ** Knowledge of returning method only after completion.
- ** After-throwing: ** notification performed on the withdrawal of anomalies from a method.
- ** Around: ** Information prior to and after the implementation of this method.
56. The cutting point
A cutting point is a point or group of connecting points at which the general knowledge will operate. The cutting point can be indicated by a pass – through or matching square.
57. What is induction?
Importing allows us to add new methods and attributes to existing classes.
58. What are object objects?
An object known from one or more facets. It is usually an algebraic object. Also means to be advised to an elephant.
59. What is agency?
Agency is the object object object object object object object object object object object. From the Angle of the guest end, the agent image is the same as the target image.
60. How many different types of autonomous agents are there?
BeanNameAutoProxyCreatorDefaultAdvisorAutoProxyCreatorMetadata autoproxying
61. What is knitting? What are the different points that should be used in weaving?
Weaving is the process of connecting or creating a known object with a class or pair of objects. Weaving can be completed at the time of compilation, loading, or transportation.
The solution is based on the faceted implementation of XML Schema formulas.
In this case, the facets are implemented by generic classes and XML-based configurations.
63. The solution is based on the realization of the tangent surface of the injection solution
In this case (based on the @AspectJ implementation), the aspect declaration in question is the same as a generic Java class with Java 5 annotations.
Spring MVC
64. What is Spring’s MVC framework?
Spring comes with a full-featured MVC framework for building Web applications. Spring can be easily integrated with other MVC frameworks, such as Struts. Spring’s MVC framework uses a control inversion to clearly separate the business object from the control logic. It also allows the binding of request parameters and business objects in an explicit formula.
65. DispatcherServlet
Spring’s MVC framework is designed around DispatcherServlet, which handles all HTTP requests and responses.
66. WebApplicationContext
The WebApplicationContext inherits the ApplicationContext and adds some features that are unique to the WEB. It is different from the generic ApplicationContext, Because it can solve the main problem and find the linked servlet.
67. What is the controller of the Spring MVC frame?
The controller provides a procedure for an inquiry, which is usually implemented through a service interface. The controller interprets the user input and converts it into a mold that is shown to the user from the visual diagram. Spring implements a control layer in a very abstract way, allowing users to create controllers for multiple purposes.
68. @ Controller injection solution
This annotation indicates that the class plays the role of controller. Spring does not require you to inherit any other controller base classes or invoke the Servlet API.
69. @ RequestMapping injection solution
The solution is used to map a URL to a class or a specific method.