Java face test-frame nine
81, what are the benefits of using the spring framework?
Lightweight: Spring is lightweight, the basic version is about 2MB.
Control reversal: Spring enables loose coupling through control inversion, and objects give them dependencies, rather than creating or locating dependent objects.
Aspect-oriented programming (AOP): Spring supports facet-oriented programming and separates application business logic from system services.
Containers: Spring contains and manages the lifecycle and configuration of objects in an application.
MVC Framework: The Spring web Framework is a well-designed framework and a good alternative to the web framework.
Transaction management: Spring provides an ongoing transaction management interface that can be extended to the local transaction to the global transaction (JTA).
Exception handling: Spring provides a convenient API for translating specific technology-related exceptions, such as those thrown by jdbc,hibernate or JDO, into consistent unchecked exceptions.
What is the usual implementation of ApplicationContext?
Filesystemxmlapplicationcontext: This container loads the beans definition from an XML file, and the full path name of the XML Bean configuration file must be supplied to its constructor.
Classpathxmlapplicationcontext: This container also loads the beans definition from an XML file, where you need to set the classpath correctly because the container will find the bean configuration in classpath.
Webxmlapplicationcontext: This container loads an XML file that defines all the beans for a Web application.
83, what is spring's dependency injection. What are the methods for dependency injection
Dependency injection, an aspect of the IOC, is a common concept, and it has many interpretations. The idea is that you don't have to create an object, and you just need to describe how it was created. You don't assemble your components and services directly in your code, but to describe which components are required in the configuration file, a container (IOC container) is responsible for assembling them.
Constructor Dependency Injection: constructor Dependency injection is implemented through a container that triggers a class constructor, which has a series of arguments, each representing a dependency on another class.
Setter method Injection: Setter method injection is when the container invokes the bean's setter method by calling the parameterless constructor or the parameterless static factory method to instantiate the bean, that is, the setter based dependency injection is implemented.
84, what is spring beans?
Spring Beans is the Java object that forms the backbone of the spring application. They are initialized, assembled, and managed by the spring IOC container. These beans are created through the metadata configured in the container. For example, define in the form of <bean/> in an XML file.
The beans of the Spring framework definition is a single piece of beans. There is an attribute "singleton" in the bean tag, which is a prototype bean if it is assigned to True,bean as a single piece. The default is true, so all beans in the spring frame are by default a single piece.
85, explains the scope of several beans that spring supports.
The spring framework supports the scope of the following five types of beans:
Singleton:bean has only one instance in each spring IOC container.
Prototype: the definition of a bean can have multiple instances.
Request: Each HTTP request creates a bean that is valid only under the Web-based Spring applicationcontext scenario.
Session: In an HTTP session, a bean definition corresponds to an instance. This scope is only valid under the Web-based spring applicationcontext scenario.
Global-session: In a global HTTP session, a bean definition corresponds to an instance. This scope is only valid under the Web-based spring applicationcontext scenario.
The default spring bean scope is singleton.
86, explains the life cycle of the bean in the spring framework.
The 1,spring container reads the bean's definition from the XML file and instantiates the bean.
2,spring fills all the properties based on the Bean's definition.
3, if the bean implements the Beannameaware interface, Spring passes the Bean's ID to the Setbeanname method.
4, if the Bean implements the Beanfactoryaware interface, spring passes beanfactory to the Setbeanfactory method.
5, if there are any beanpostprocessors,spring associated with the bean, they are called within the Postprocesserbeforeinitialization () method.
6, if the Bean implements Intializingbean, call its Afterpropertyset method, and call this initialization method if the bean declares an initialization method.
7, if there are beanpostprocessors and bean associations, the Postprocessafterinitialization () method of these beans will be invoked.
8, if the bean implements Disposablebean, it calls the Destroy () method.
87, how to inject a Java collection into spring.
Spring provides configuration elements for the following collections:
The <list> type is used to inject a column of values that allows the same value.
The <set> type is used to inject a set of values that do not allow the same value.
The <map> type is used to inject a set of key-value pairs, and both the key and the value can be of any type.
The <props> type is used to inject a set of key-value pairs, with keys and values that can only be string types.
88, explain the different ways of automatic assembly.
There are five automated assembly methods that guide the spring container to use automatic assembly for dependency injection.
No: The default approach is to assemble without automatic assembly by explicitly setting the Ref property.
ByName: Automatically assembled with parameter names, the spring container found in the configuration file that the bean's Autowire attribute was set to ByName, after which the container attempted to match, assemble, and Bean with the same name as the Bean's properties.
Bytype:: Automatically assembled by parameter type, the spring container found in the configuration file that the bean's Autowire property was set to Bytype, after which the container attempted to match, assemble, and have the same type of bean as the bean's properties. If more than one bean meets the criteria, an error is thrown.
Constructor: This approach is similar to Bytype, but to provide constructor parameters, an exception is thrown if there is no determined constructor parameter type with parameters.
AutoDetect: First try to use constructor from the dynamic assembly, and if it is not working, use the Bytype method.
What are the advantages of the 89,spring framework's transaction management?
It provides a constant programming pattern for different transaction APIs, such as JTA,JDBC,HIBERNATE,JPA and JDO.
It provides a simple set of APIs for programmatic transaction management rather than some complex transaction APIs such as
It supports declarative transaction management.
It integrates well with spring's various data access abstraction layers.
90. What is a Java-based spring annotation configuration? Give some examples of annotations.
Java-based configuration allows you to perform most of your spring configuration, rather than through XML files, with the help of a small amount of Java annotations.
Take the @configuration annotation as an example, it is used to mark the definition of a class as a bean, which is used by the spring IOC container. Another example is the @bean annotation, which indicates that this method will return an object and register it as a bean into the spring application context.
Java Companion public number of major companies to organize a number of commonly used interview pen questions, for everyone in the spare time to learn some of the topics, accumulated over time, wait for the interview, everything is ripe, the interview will naturally be easier.