SpringMVC 3.0 常用注解简介
1. 注册注解处理器 命名空间<context:component-scan/> 首先,如果要使注解工作,则必须配置component-scan 。该配置的功能为:启动包扫描功能,以便注册带有@Controller、@Service、@repository、@Component等注解的类成为spring的bean。例: <context:component-scanbase-package="com.tgb.web"/> base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。还允许定义过滤器将基包下的某些类纳入或排除。 Spring 支持以下 4 种类型的过滤方式: 1) 注解org.example.SomeAnnotation 将所有使用SomeAnnotation注解的类过滤出来 2) 类名指定org.example.SomeClass 过滤指定的类 3) 正则表达式com.kedacom.spring.annotation.web..* 通过正则表达式过滤一些类 4) AspectJ 表达式 org.example..*Service+ 通过AspectJ 表达式过滤一些类 正则表达式的过滤方式举例: 注解的过滤方式举例: 2. 启动Spring MVC 的注解功能