springmvc注解整理
2016-11-30 22:18
127 查看
–定义Bean的注解
@Controller
@Controller(“Bean的名称”)
定义控制层Bean,如Action
@Service
@Service(“Bean的名称”)
定义业务层Bean
@Repository
@Repository(“Bean的名称”)
定义DAO层Bean
@Component
定义Bean, 不好归类时使用.
–自动装配Bean (选用一种注解就可以)
@Autowired (Srping提供的)
默认按类型匹配,自动装配(Srping提供的),可以写在成员属性上,或写在setter方法上
@Autowired(required=true)
一定要找到匹配的Bean,否则抛异常。 默认值就是true
@Autowired
@Qualifier(“bean的名字”)
按名称装配Bean,与@Autowired组合使用,解决按类型匹配找到多个Bean问题。
@Resource JSR-250提供的
默认按名称装配,当找不到名称匹配的bean再按类型装配.
可以写在成员属性上,或写在setter方法上
可以通过@Resource(name=”beanName”) 指定被注入的bean的名称, 要是未指定name属性, 默认使用成员属性的变量名,一般不用写name属性.
@Resource(name=”beanName”)指定了name属性,按名称注入但没找到bean, 就不会再按类型装配了.
@Inject 是JSR-330提供的
按类型装配,功能比@Autowired少,没有使用的必要。
–定义Bean的作用域和生命过程
@Scope(“prototype”)
值有:singleton,prototype,session,request,session,globalSession
@PostConstruct
相当于init-method,使用在方法上,当Bean初始化时执行。
@PreDestroy
相当于destory-method,使用在方法上,当Bean销毁时执行。
–声明式事务
@Transactional
@Component(组件)@Service(服务层)@Controller(控制层)@Repository(数据库访问层)
3.有了,另一个标签根本可以移除掉,因为已经被包含进去了。
提供两个子标签:和各代表引入和排除的过滤。
filter标签在Spring3有五个type,如下:
Filter Type
Examples ExpressionDescriptionannotationorg.example.SomeAnnotation符合SomeAnnoation的target classassignableorg.example.SomeClass指定class或interface的全名aspectjorg.example..*Service+AspectJ语法regexorg.example.Default.*Regelar Expressioncustomorg.example.MyTypeFilterSpring3新增自訂Type,实作org.springframework.core.type.TypeFilter
@Controller
@Controller(“Bean的名称”)
定义控制层Bean,如Action
@Service
@Service(“Bean的名称”)
定义业务层Bean
@Repository
@Repository(“Bean的名称”)
定义DAO层Bean
@Component
定义Bean, 不好归类时使用.
–自动装配Bean (选用一种注解就可以)
@Autowired (Srping提供的)
默认按类型匹配,自动装配(Srping提供的),可以写在成员属性上,或写在setter方法上
@Autowired(required=true)
一定要找到匹配的Bean,否则抛异常。 默认值就是true
@Autowired
@Qualifier(“bean的名字”)
按名称装配Bean,与@Autowired组合使用,解决按类型匹配找到多个Bean问题。
@Resource JSR-250提供的
默认按名称装配,当找不到名称匹配的bean再按类型装配.
可以写在成员属性上,或写在setter方法上
可以通过@Resource(name=”beanName”) 指定被注入的bean的名称, 要是未指定name属性, 默认使用成员属性的变量名,一般不用写name属性.
@Resource(name=”beanName”)指定了name属性,按名称注入但没找到bean, 就不会再按类型装配了.
@Inject 是JSR-330提供的
按类型装配,功能比@Autowired少,没有使用的必要。
–定义Bean的作用域和生命过程
@Scope(“prototype”)
值有:singleton,prototype,session,request,session,globalSession
@PostConstruct
相当于init-method,使用在方法上,当Bean初始化时执行。
@PreDestroy
相当于destory-method,使用在方法上,当Bean销毁时执行。
–声明式事务
@Transactional
@Component(组件)@Service(服务层)@Controller(控制层)@Repository(数据库访问层)
3.有了,另一个标签根本可以移除掉,因为已经被包含进去了。
提供两个子标签:和各代表引入和排除的过滤。
filter标签在Spring3有五个type,如下:
Filter Type
Examples ExpressionDescriptionannotationorg.example.SomeAnnotation符合SomeAnnoation的target classassignableorg.example.SomeClass指定class或interface的全名aspectjorg.example..*Service+AspectJ语法regexorg.example.Default.*Regelar Expressioncustomorg.example.MyTypeFilterSpring3新增自訂Type,实作org.springframework.core.type.TypeFilter
相关文章推荐
- SpringMVC注解整理
- SpringMVC的注解整理总结
- SpringMVC 常用注解整理
- springMVC的文件上传(注解)
- SpringMVC缓存注解@Cacheable、@CacheEvict、@CachePut使用
- springmvc3.2+spring+hibernate4全注解方式整合(三)
- springMVC的注解1
- SpringMVC + ehcache( ehcache-spring-annotations)基于注解的服务器端数据缓存
- 基于注解的SpringMVC简单介绍
- springMVC事务注解拾遗
- SpringMVC Controller注解
- SpringMVC-3.注解方式实现(常用)
- SpringMVC学习(5): RequestParam 注解
- springmvc mybatis 基于全注解事务配置注意事项
- springmvc学习笔记(常用注解)
- SpringMVC-----6、SpringMVC注解启用
- Springmvc 注解@PathVariable
- [SpringMVC]自定义注解实现控制器访问次数限制(转载)
- SpringMVC常用的注解
- springmvc注解知识点汇总