欢迎来到天天文库
浏览记录
ID:41272578
大小:34.42 KB
页数:10页
时间:2019-08-20
《Spring注解详解》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Spring 注解详解目录一、注解 说明21.使用简化配置22.使用Bean定义注解23.Spring 支持以下4 种类型的过滤方式:2二、注解介绍21.@Controller32.@Service33.@Autowired44.@RequestMapping45.@RequestParam56.@ModelAttribute67.@Cacheable 和@CacheFlush78.@Resource79.@PostConstruct 和@PreDestroy810.@Repository811.@Component (不推荐使用)812.@Scope813.@
2、SessionAttributes914.@InitBinder915.@Required916.@Qualifier10一、注解 说明 1.使用简化配置 将隐式地向Spring 容器注册以下4 个BeanPostProcessor:AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessor PersistenceAnnotationBeanPostProcessorRequiredAnnotationBeanPostProc
3、essor 2.使用Bean定义注解 如果要使注解工作,则必须配置component-scan ,实际上不需要再配置annotation-config。 base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。还允许定义过滤器将基包下的某些类纳入或排除。 3.Spring 支持以下4 种类型的过滤方式: 1)注解 org.example.SomeAnnotation 将所有使用SomeAnnotation 注解的类过滤出来 2) 类名指定 org.example.SomeClass 过滤指定的类 3)正则表达式 com
4、.kedacom.spring.annotation.web..* 通过正则表达式过滤一些类 4)AspectJ 表达式 org.example..*Service+ 通过AspectJ 表达式过滤一些类 二、注解介绍 注解种类:1) @Controller 2) @Service 3) @Autowired 4) @RequestMapping 5) @RequestParam 6) @ModelAtt
5、ribute 7) @Cacheable 8) @CacheFlush 9) @Resource 10) @PostConstruct 11) @PreDestroy 12) @Repository 13) @Component (不推荐使用) 14) @Scope 15) @SessionAttributes 16) @InitBinder 17
6、) @Required 18) @Qualifier1.@Controller 例如 @Controller public class SoftCreateController extends SimpleBaseController {} 或者 @Controller("softCreateController") 说明 : @Controller 负责注册一个bean 到spring 上下文
7、中,bean 的ID 默认为类名称开头字母小写2.@Service 例如 @Service public class SoftCreateServiceImpl implements ISoftCreateService {} 或者 @Service("softCreateServiceImpl") 说明 @Service 负责注册一个bean 到spring 上下
8、文中,bean 的ID
此文档下载收益归作者所有