注解 | 作用 | 例子 |
---|---|---|
@SuppressWarnings | 忽略警告 | 类上添加此注解:@SuppressWarnings("serial"),能消除警告:The serializable class xxx does not declare a static final serialVersionUID field of type long |
在applicationContext.xml中注册<context:component-scan base-package=”pagkage1[,pagkage2,…,pagkageN]”/> |
如果某个类的头上带有特定的注解【@Component/@Repository/@Service/@Controller】,就会将这个对象作为Bean注册进Spring容器 | <context:component-scan base-package="cn.gacl.dao.impl,cn.gacl.service.impl,cn.gacl.action"/> |
@Controller | 对应表现层的Bean,也就是Action | |
@Scope("prototype") 或 @Scope("singleton") | @Scope("prototype")表示将Action的范围声明为原型,可以利用容器的scope="prototype"来保证每一个请求有一个单独的Action来处理,避免struts中Action的线程安全问题;spring 默认scope 是单例模式(scope="singleton") | |
@Service | 对应的是业务层Bean | |
@Repository | 对应数据访问层Bean | |
@Component | @Component 是 @Controller @Service @Repository 的父类,不能在语义上表明这个类所处的层级,因此不推荐使用 |