Ch02 Annotation

7/25/2019 SpringJava

# Annotation

image-20230425183500643

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.yang.pojo"></context:component-scan>

1
2
3
image-20230425183513909

image-20230425183536262

可以使用value指定bean的名字,否则取第一个字母小写的类名)

步骤:

  1. 先在要创建bean的class里加入注解:括号里为bean的id

image-20230425183553122

  1. 配置文件:要使用到context命名空间,扫描包内所有的class

可以使用属性resource-pattern来指定扫描的资源,如resource-pattern = “repository/*.class”表示只扫描repository下面的包

image-20230425183612052

image-20230425183622286

image-20230425183630454

image-20230425183643411

image-20230425183651863

# 引入外部文件

image-20230425183735619

# Spel表达式

image-20230425183748402

Last Updated: 11/19/2024, 1:54:38 PM