@Repository: 注解在持久层中,具有将数据库操作抛出的原生异常翻译转化为spring的持久层异常的功能。
参考:@Component, @Repository, @Service的区别
@Autowired: 通过 @Autowired的使用来消除 set ,get方法。
在applicationContext.xml中加入:
<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
参考:Spring注解标签详解@Autowired @Qualifier等
@Service: 用于标注业务层组件
首先,在applicationContext.xml文件中加一行:
<context:component-scan base-package="com.hzhi.clas"/>
参考:@Service注解的使用
@Controller: 用于标注控制层组件
@Component: 对那些比较中立的类进行注释(当组件不好归类的时候,我们可以使用这个注解进行标注)
@Transactional: 可以作用于接口、接口方法、类以及类方法上。当作用于类上时,该类的所有 public 方法将都具有该类型的事务属性,同时,我们也可以在方法级别使用该标注来覆盖类级别的定义。
参考:spring的@Transactional注解详细用法
@ContextConfiguration: 导入配置文件(如: Spring整合JUnit4测试时,使用注解引入多个配置文件)
参考:spring4.0之二:@Configuration的使用
@CrossOrigin: 用来处理跨域请求
参考:HTTP访问控制(CORS)
@Configuration: 用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。
参考:Spring中Configuration的理解
@ComponentScan: 会自动扫描包路径下面的所有@Controller、@Service、@Repository、@Component 的类
参考:spring4.0的@ComponentScan自动描述组件,定制扫描规则
@EnableAutoConfiguration: 自动载入应用程序所需的所有Bean——这依赖于Spring Boot在类路径中的查找。
参考:springboot注解之:@EnableAutoConfiguration
@Scope: 可以显示指定 bean 的作用范围