The way springMvc automatically equips beans

Spring is a framework that is often used in our projects. Using bean injection in spring can reduce code. Project injection of beans is the most basic functionality in a project.

There are three main injection methods in spring.

1. java display injection

  

2.xml display injection

  Configure <context-component-scan base-package = 'com.bao'> in the configuration xml file in the project

3. Implicit injection of java

  1) Add the @compoment annotation to the class

  @compoment(name)

  public class beanZhu imp beani ();

  2) Increase the config of spring scan bean

  @configuration

  @ComponentScan

  public class beanConfig()

Note that @name can be used to replace the @component alternative.

 

  

  

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324494384&siteId=291194637