Use SMM framework for developing enterprise applications ----- face questions

In Spring bean

  Spring IoC container body and the managed objects of the application, is called bean.

  Simply put, the bean is initialized by the IoC container, assembling the object and management

  Spring in the embodiment are single default bean (scope = "singleton" default)

  We can set multiple cases (scope = "prototype")

scope of the bean

  When the scope = "singleton"

    Singleton embodiment is a single type, that is, when it is created from the container and automatically creates an object of the bean

    Whether or not you use him there, and every time to get the objects are the same object

  When scope = when "prototype"

    Prototype is a prototype type, it does not instantiated when we create container

    But when we get the bean when it will go to create an object, and every time we get to the target is not the same object

 

  Examples 1. Bean acquired by BeanFactory or ApplicationContext

  2.set property injection

  3. If the Bean implementation BeanNameAware interface, the call setBeanName (String name) method sets the name attribute of the Bean

  4. If the Bean implementation BeanFactoryAware interface, the call setBeanFactory (BeanFactory beanFactory) method, set to create the Bean Factory

  5. If there is defined BeanPostProcessor interface, the interface is called postProcessBeforeInitialization (Object bean, String beanName) Method

    The method may increase the additional processing operations Bean instance. Can be a global unified process for all Bean, it will automatically find the class that implements this interface are enhanced when all ApplicationContext Bean initialization.

  6. If InitializingBean Bean implements the interface, and the interface has  @PostConstruct modification method, for performing the method ( the method is performed in the annotation postProcessBeforeInitialization BeanPostProcessor's ), and then perform afterPropertiesSet () for;

    This method has no parameters, the Bean can not be processed, such as a log can be increased, like the read operation of the configuration file.

  7. If Bean custom methods init-method specified, then call the method

  8. BeanPostProcessor interface then calls postProcessAfterInitialization (Object bean, String beanName) Method

  9. If DisposableBean Bean implements an interface, the interface is called Destory () method. InitializingBean with similar, if the interface is specified @PreDestory annotated modified method, will first call the method.

  Bean 10. If destory-method specified method, this method is performed

  The above is Bean lifecycle order.

  Description:

  1.afterPropertiesSet () and init-method What is the difference

    afterPropertiesSet () relies InitializingBean interface, it must implement the interface to use when Bean definitions, the code has some intrusion. init-method only need to specify which method you want to call it. Similarly DiaposableBean the Destory () method and destory-method.

    However afterPropertiesSet () method of the efficiency is higher than the specified init-method, which is called directly executed, but the method requires init-method specified invoked by reflection.

    init-method and method destory-method specified must be a non-parametric method, otherwise, initialization error.

 Interview questions

  1. What are different IOC dependency injection

    Direct injection (Seter)

    Constructor injection

    Name tag implanted P

    Injecting into the set (<constructor-ary> </ constructor-ary>)

    The default injection (autowire = "byType" and autowire = "byName") to the domain attributes

  2.java nine implicit objects which

    request request object type javax.servlet.ServletRequest Scope Request object is mainly used for processing client requests, in (page forward, get cookie) used

    response in response to the type of object javax.servlet.SrvletResponse scope Page responding to client requests for processing, using (redirect page) in

    pageContext page context object type javax.servlet.jsp.PageContext Page scope for obtaining a page context may be built for additional eight target page by the object

    session session object type javax.servlet.http.HttpSession scope Session is called a session in the network, a session is a call (save login state) between the browser and server

    application application scope Application Object Type javax.servlet.ServletContext like global variables, for a total data storage applications (get real path when uploading)

    out output object type javax.servlet.jsp.JspWriter Page scope for outputting information objects within a web browser, a data output finished, to close the output stream

    config configuration object types javax.servlet.ServletConfig scope Page information obtained is used to configure the server

    page page object type javax.lang.Object scope Page behalf jsp itself, only in the jsp page is legitimate

    Exceptions object types javax.lang.Throwable scope exception page for exception handling occurs jsp pages

  3. What is the database indexes and constraints are

    Index: a pointer to data in the table, the books to the data, with respect to each section of the database tables, and the book is indexed directory.

    Constraint: The purpose of the design integrity of the database is to prevent the presence of data does not match the semantics of the database, to prevent the input and output error information

  Works 4.DAO, can not overloaded

    Dao is the interface Mapper interface. Value mapping file namespace; the interface method name is the id mapping file Mapper Statement of value;

    Mapper interfaces in the method, is not overloaded, because it is using to save the fully qualified name + method name and look for strategies

  5.Mybatis how to page through, what is the principle

    Mybatis RowBounds objects using paging, it is for the memory paging ResultSet result set to perform, rather than the physical page. Parameter may be directly written with the physical pages in the physical page is accomplished sql function may be used to complete the physical page tab widget.

    Principle: using the plugin interface is provided Mybatis achieve custom plug, sql interception to be performed in the method of intercepting the plug, and then rewrite the sql, according dialect dialect, add statements and physical page corresponding to the physical paging parameters.

Guess you like

Origin www.cnblogs.com/haohanwuyin/p/11756610.html