SpringIOC container-use annotations to configure Bean-xml scanning annotations

SpringIOC container to use annotations to configure Bean, then you must have aop jar package

There are four main annotations used to represent Bean

@Component

@Service 

@Controller

@Repository

It is useless to add light to the annotations. You need to scan these annotations in the xml file. The xml scan configuration is as follows

The base-package here means that Spring will only scan the com.llf.annotation.bean package and the classes in its sub-packages regarding the four annotations above

<context:component-scan base-package="com.llf.annotation.bean"></context:component-scan>

The Value attribute can be added in the middle of these four annotations to indicate its name in the SpringIOC container, that is, the parameter in the getBean method.

 

The context: component-scan tag also has many attributes, which are used to retrieve scans for various requirements. You can refer to:

context: component-scan instructions

Guess you like

Origin www.cnblogs.com/linglongfang/p/12727451.html