• spring中常用注解


    @Autowired:自动通过类型,名字。如果不能唯一自动装配使用@Qualifier(value="""),也可放在setter方法上

    @Nullable:允许参数为空

    @Resources:自动通过名字然后在类型

    @Component:组件,放在类上,说明该类被Spring管理了就是所谓的bean,放在pojo层

    @Value:给属性赋值,也可以放在setter方法上。

    @Repository:组件,相当于Component,但放在Dao层

    @Controller:组件,相当于Component,但放在Controller层

    @Component,@Repository,@Controller被扫描入IOC容器中称为组件

    @Scope("singleto"):单例模式或原型模式(prototype)

    纯java的配置类,相当于xml文件

    @Configuration:这个也会让Spring容器托管,注册到容器中,因为他本身也是一个@Component,@Configuration代表这是一个配置类

    @ComponentScan(" "):扫描包

    @Bean:相当于以前的bean标签。名字相当于方法名,返回值相当于bean标签中的class属性 new AnnotationConfigApplicationContext(配置类.class);

    @Import(.class):导入另一个配置类

    spring用注解需要开启注:

    <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
                https://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context
                https://www.springframework.org/schema/context/spring-context.xsd">
        
            <!--开启注解支持-->
            <context:annotation-config/>
            <!--指定要扫描的包,则该包下的注解能生效-->
            <context:component-scan base-package=""/>
        </beans>
  • 相关阅读:
    rsync命令 SCP命令
    Linux 性能分析 工具命令
    ntp时间服务器 时间同步
    Linux 邮件服务
    linux 手工释放内存 高内存 内存回收 方法思路
    LVM 逻辑卷 (logica volume manager)
    Linux 磁盘原理与管理 (分区 挂载)
    linux中查看nginx、apache、php、mysql配置文件路径
    shell脚本 监控ps 不存在则重启
    Shell脚本 一键重启
  • 原文地址:https://www.cnblogs.com/Difcipo/p/13052385.html
Copyright © 2020-2023  润新知