@Repository、@Service、@Controll…
来源:互联网 发布:小额贷款骗局知乎 编辑:程序博客网 时间:2024/06/05 16:45
这里简要列些摘要供查询:
spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring的开发。
如此,我们就不再需要在 XML 中显式使用<bean/> 进行Bean 的配置。Spring在容器初始化时将自动扫描 base-package 指定的包及其子包下的所有 class文件,所有标注了 @Repository的类都将被注册为 Spring Bean。
为什么 @Repository 只能标注在 DAO类上呢?这是因为该注解的作用不只是将类识别为Bean,同时它还能将所标注的类中抛出的数据访问异常封装为 Spring的数据访问异常类型。Spring本身提供了一个丰富的并且是与具体的数据访问技术无关的数据访问异常结构,用于封装不同的持久层框架抛出的异常,使得异常独立于底层的框架。
Spring 2.5 在@Repository的基础上增加了功能类似的额外三个注解:@Component、@Service、@Constroller,它们分别用于软件系统的不同层次:
@Component是一个泛化的概念,仅仅表示一个组件 (Bean),可以作用在任何层次。
@Service 通常作用在业务层,但是目前该功能与@Component 相同。
@Constroller 通常作用在控制层,但是目前该功能与@Component 相同。
通过在类上使用 @Repository、@Component、@Service 和@Constroller 注解,Spring会自动创建相应的 BeanDefinition 对象,并注册到ApplicationContext 中。这些类就成了 Spring受管组件。这三个注解除了作用于不同软件层次的类,其使用方式与@Repository 是完全相同的。
另外,除了上面的四个注解外,用户可以创建自定义的注解,然后在注解上标注@Component,那么,该自定义注解便具有了与所@Component 相同的功能。不过这个功能并不常用。
————原文地址:http://blog.csdn.net/ye1992/article/details/19971467
0 0
- @Repository、@Service、@Controll…
- @Repository、@Service、@Co…
- @Component @Service @Controller @Repository
- :@Repository、@Service 和 @Controller。
- @Component、@Repository @Service、@Controller
- @Component @Service @Controller @Repository
- @Component,@Service,@Controller,@Repository
- @Repository @Service @Controller @Component
- Controller->Service->Repository
- @Repository、@Service、@Controller、@Component
- @Component、@Repository、@Service、@Controller
- Traffic Controll
- 解释@Component @Controller @Service @Repository
- 注解@Component @Controller @Service @Repository
- @Repository、@Service、@Controller 和 @Component
- 解释@Component @Controller @Service @Repository
- 解释@Component @Controller @Service @Repository
- 解释@Component @Controller @Service @Repository
- 满屏幕的线程Hibernate结合Servlet…
- SSH框架特例实战【一】(SpringMVC…
- 为何有DAO与Service层?为何先搞Da…
- SSH框架特例实战【二】关于Autowir…
- java.lang.NoSuchMethodError:&nbs…
- @Repository、@Service、@Controll…
- Netbeans许可证,是否能商用,是否…
- Setting property &#039…
- C++函数模板
- 一阶段实验性稳定JavaEE系统(包的…
- JAVA CAS原理深度分析
- SSH中操作Hibernate的事务与删除数…
- iOS逆向工程之Hopper中的ARM指令
- Netbeans IDE中连接数据库,自动生…