zoukankan      html  css  js  c++  java
  • spring 注解开发

    spring 注解开发

    • 注解:为了代替配置文件,让配置信息和java代码看起来更直观   (注,JDK1.8和spring4.0以上才兼容)

                       也起解释说明和检查的作用,如@Override可以检查是否重写了父类方法,有报错提示

                 

    • 缺点:修改配置文件要打开源码修改,之后再重新编译
    • 注解开发前提

                开启context的命名空间

                设置扫描器的路径包名 

                 

    • @Component("person")  不写则默认类名首字母小写   (IOC注解

                 三个衍生注解:@Controller    @Service  @Repository

    • @Autowired(required=true)  不写条件默认true,代表注入是否必须找到参数,否则会报错       (DI注解) 和@Value结合使用可以给成员变量赋值
    • @Resource (和@Autowired一样,@Autowired按 byType 自动注入,@Resource按 byName 自动注入)
    • @PostConstruct (init)  @PreDestory (destory)   生命周期相关
    • @Scope 默认singleton单例,非单例:prototype
    •                                                          @Configuration 定义在类上,表示当前类是一个bean资源配置类

                 配合使用,则无需xml配置文件 

                                                                        @Bean 定义在方法上,方法的返回值就是bean资源

  • 相关阅读:
    Springboot整合activeMq
    linux下安装activeMq
    linux下配置jdk
    thinkphp5 集成 redis
    linux下安装redis
    tp5集成swagger
    lombok
    idea下springboot环境搭建
    Mac环境下maven安装配置
    idea环境下搭建swagger2接口文档
  • 原文地址:https://www.cnblogs.com/sycamore0802/p/11177787.html
Copyright © 2011-2022 走看看