spring配置学习--笔记

本文介绍了Spring框架的基本概念包括IOC(控制反转)和AOP(面向切面编程),详细讲解了Spring的配置方式,包括XML配置文件和Java配置类的使用方法,并列举了一些常用注解及其作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ioc;控制反转
aop:面向切面编程

1---------------spring包名------------

---------------spring包名-------------
<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    --------------------------------------------------------------------

2------------ Beans.xml配置头文件(包含自动注解)------------

  ---------------- Beans.xml配置头文件(包含自动注解)----------------------

    <?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
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    <!--    注解支持-->
        <context:component-scan base-package=""/>自动扫描托管类与 @Component 对用应---以xml文件配置spring
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");//以xml配置时候new
        <context:annotation-config/>允许自动注解<!--    注解支持-->

    </beans>
    -----------------------------------------------------------------------

3-------------部分注解--------------------

-------------部分注解--------------------

    1.@Configuration       
    						 //这是一个配置类用来以java代码作为spring配置文件使用
    2. ApplicationContext context = new AnnotationConfigApplicationContext(anno.class);  
    				 		//以java配置时候new
    3.@Component          
    				组件 //说明Component被spring托管的组件
    			衍生出:
         			 		  dao【@Reposit】
          					  service【@Service】
           					 controller【@Controller】
          					  //三个功能一样
   4. @ComponentScan("")
    					//	java配置中使用;对比 <context:component-scan base-package=""/>自动扫描托管类与 5.@Component 
    					//对用应------以xml文件配置spring
  6.  @import(...class)
    					//导入java配置文件
  7.  @Autowired            
     					//    自动导入类    //自动装配依赖通过类型。
    -如果@Autowired不能自动装配唯一,需要@Qualifier(value="")
  8.  @Nullable 
    					//字段标记了这个注解,说明这个字段可以为null
  9.  @Resoure
    					//自动装配通过名字。类型

  10.  @Value("")            
    					//注入值

    11.@Scope("")
    					//值有prototype和single。。多例和单例实现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值