Java frameworks articles Interview (9)

Now spring is undoubtedly the hottest in Java framework, using a wide range, almost every company will be involved in the interview spring and databases, you may not be familiar with Struts, but it must not show for spring do not understand. Ninth win in an interview published article about the whole spring constant test sites. Database will spend five most important question type is often introduced in the back

 

81 What are the benefits of using Spring framework is?

        Lightweight: the Spring is lightweight, basic version is about 2MB.

        Inversion of Control: the Spring Inversion of Control achieved by loosely coupled, objects are given their dependencies instead of creating them or find dependent objects.

        Aspect-oriented programming (the AOP): the Spring aspect-oriented programming support, and separating the business logic of the application and system services.

        Container: the Spring contains and manages the lifecycle and configuration objects in the application.

        MVC framework : Spring WEB framework of a well-designed framework, is a good alternative to Web framework.

        Transaction management: the Spring provides an ongoing transaction management interface can be extended to up to lower local transaction to a global transaction (JTA).

        Exception handling: the Spring API provides a convenient technique related to specific abnormalities (such as a JDBC, Hibernate or JDO thrown) into uniform unchecked exceptions.

 

What is usually 82. ApplicationContext implementation is?

        FileSystemXmlApplicationContext: This container load of beans from a defined XML file, XML Bean configuration file full path name must be provided to its constructor.

        ClassPathXmlApplicationContext: This container is also loaded with the definition of beans from an XML file, where you need to correctly set the classpath because the bean container will find in the classpath configuration.

        WebXmlApplicationContext: This container load an XML file that defines all bean a WEB application.

 

83, what is Spring's dependency injection ? Dependency injection method which

        Dependency injection is an aspect of the IOC, the concept is generally, it has more than one interpretation. This concept is not to say you create an object, but only need to describe how it is created. You are not in your code directly assembled components and services, but to describe what services which components required in the configuration file, after a container (IOC container) is responsible assemble them together.

        Constructor dependency injection: constructor dependency injection triggers a class constructor is achieved through the vessel, such a series of parameters, each representing a dependency on other classes.

        Setter injection method: Setter injection method is a container after passing through the no-argument constructor or no-argument static factory method to instantiate bean call, calling setter methods of the bean, i.e. realized on a setter dependency injection.

 

84, what is the Spring beans?

        Spring beans are java objects that form the backbone of Spring applications. They are initialized Spring IOC container, assembly, and management. These beans are created using metadata container configuration. For example, defined in the XML file <bean /> form.

        Spring framework defined beans beans are a single piece. Has a property "singleton" in the bean tag, if it is assigned to TRUE, bean is a single piece, otherwise it is a prototype bean. The default is TRUE, so all the beans in the Spring Framework default is a single piece.

 

85, Spring supports the interpretation of several bean scope.

        Spring framework supports the following five bean scope:

        Singleton:  the bean only one instance of each Spring ioc container.

        prototype: a bean definition can have multiple instances.

        request: every http request creates a bean, this scope is only valid in the case of Spring ApplicationContext web-based.

        session: a HTTP Session, the definition to a bean. Only valid in the case of Spring ApplicationContext web-based.

        global-session: a global HTTP Session, the definition to a bean. Only valid in the case of Spring ApplicationContext web-based.

Default Spring bean scope is Singleton.

 

86, explained the Spring Framework bean life cycle.

        1, Spring container bean definition read from the XML file, and examples of the bean.

        2, Spring fill all the attributes according to the definition of the bean.

        3, if the interface bean implements BeanNameAware, Spring passed to the bean ID setBeanName method.

        4. If the Bean implements BeanFactoryAware interfaces, Spring passed beanfactory to setBeanFactory method.

        5, if there is any BeanPostProcessors associated with the bean, Spring will call them within postProcesserBeforeInitialization () method.

        6. If the bean implements IntializingBean, and call it afterPropertySet method, if declared bean initialization method, call this initialization method.

        7, if there is BeanPostProcessors and associated bean, the bean's postProcessAfterInitialization () method is called.

       8, if the bean implements the DisposableBean, it calls the destroy () method.

 

87, in Spring how to inject a collection of java?

Spring element arranged to provide the following set:

    <List> type a value for injection, allowing the same value.

    <Set> type for injecting a set of values, not have the same value.

    <Map> type for injecting a key-value pair, the key can be any type and value.

    <Props> type for injecting a key-value pair, the key and value can only type String.

 

88, to explain the automatic assembly of different ways.

There are five ways automatic assembly, to guide the container Spring Dependency injection mode with automatic assembly.

        NO : The default mode is not automatic assembly, the assembly is performed by explicitly setting the ref attribute.

        byName: automatic assembly parameter names, Spring found bean container property is set to the autowire byname in the configuration file, after trying to match the container, and the assembly of the bean property with the same name bean.

        :: byType parameter type automatic assembly, Spring found bean container property is set to the autowire byType in the configuration file, after trying to match the container, and the assembly of the bean property with the same type of bean. If more than one bean qualify, then throw an error.

        constructor: This mode is similar to byType, but the constructor parameters to be provided to, if not determined constructor parameter type arguments, it will throw an exception.

        autodetect: First, try to use the constructor to automatically assemble, if not work, use byType way.

 

89, transaction management Spring Framework What are the advantages?

        It is a different transaction API such as JTA, JDBC, Hibernate, JPA and JDO, providing a constant programming mode.

        It provides a simple API for programmatic transaction management and not some complex transactions such as API

        It supports declarative transaction management.

        It and a variety of data access abstraction layer Spring was well integrated.

 

90. What is a Java-based Spring configuration annotations? Give some examples of annotations.

        Java-based configuration, allows you with the help of a small amount of Java annotations, perform most of your Spring configuration rather than through an XML file.

        In @Configuration annotation example, it can be used to mark the class defined as a bean, and is used Spring IOC container. Another example is @Bean annotations, which represents this method will return an object registered as a bean into Spring application context.

Guess you like

Origin www.cnblogs.com/mxb0611/p/11914830.html