Spring常用注解含义

1、@Reponsitory

@Reponsitory使用后,在启动类上需要添加@MapperScan("xxx.xxx.xxx.mapper")注解

2、@Mapper

@Mapper注解使用后相当于@Reponsitory加@MapperScan注解,会自动进行配置加载

3、@MapperScan

作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
添加位置:是在Springboot启动类上面添加

4、@Bean

@Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里。添加的bean的id为方法名

@Configuration
public class AppConfig {
    @Bean
    public TransferService transferService() {
        return new TransferServiceImpl();
    }
}

这个配置就等同于之前在xml里的配置

<beans>
    <bean id="transferService" class="com.acme.TransferServiceImpl"/>
</beans>

5、@Configuration

加入@Configuration 注解,表明这就是一个配置类。作为配置类 替换 xml配置文件

posted @ 2021-10-10 18:52  有何和不可  阅读(165)  评论(0)    收藏  举报