spring framework

来源:互联网 发布:网络文明公益广告 编辑:程序博客网 时间:2024/05/11 02:16
下面是引用spring framework开发手册中的一段话“

Spring 2.5引入了更多典型化注解(stereotype annotations):

 @Component、@Service和 @Controller。

@Component是所有受Spring管理组件的通用形式;

而@Repository、@Service和 @Controller则是@Component的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。

也就是说,你能用@Component来注解你的组件类,但如果用@Repository、@Service 或@Controller来注解它们,你的类也许能更好地被工具处理,或与切面进行关联。例如,这些典型化注解可以成为理想的切入点目标。当然,在Spring Framework以后的版本中, @Repository、@Service和 @Controller也许还能携带更多语义。如此一来,如果你正在考虑服务层中是该用@Component还是@Service,那@Service显然是更好的选择。同样的,就像前面说的那样, @Repository已经能在持久化层中进行异常转换时被作为标记使用了。”


注解的方式,但是spring的注入是在filter和listener之后的,(顺序是这样的listener >>  filter >> servlet >>  spring )

0 0
原创粉丝点击