首页 > 其他分享 >Spring学习

Spring学习

时间:2024-03-13 14:56:15浏览次数:15  
标签:Spring Component Bean ComponentScan 学习 bean Configuration

目录

Spring1

3、HelloSpring

4、IOC创建对象方式

4.1 方式一
4.2 方式二

5、Spring配置

5.1 别名
5.2 Bean的配置
5.3 import

Spring2

Spring3

单例模式(面试)

Spring4

使用Java来配置bean

spring官方的文档有这样一段描述,context:component-scan base-package/@ComponentScan will do an auto-scanning. Assuming each class that has to become a bean is annotated with a correct annotation like @Component (for simple bean) or @Controller (for a servlet control) or @Repository (for DAO classes) and these classes are somewhere under the package, Spring will find all of these and create a bean for each one.
这里@componetScan或context:component-scan base-package会扫描将带有注解@Component的类注册为bean。无关@Configuration和@Bean

pojo类包

1、@Component

config包

1、@Configuration
2、@ComponentScan("com.github.pojo")
3、在方法上添加注解@Bean

1+(1+3)@Component+(@Configuration+@Bean)
1+(2+3)@Component+(@ComponentScan+@bean)
1+(3)@Component+(@bean)
(2+3)(@ComponentScan+@bean )
(1+3)(@Configuration+@bean)

Spring5

Spring6

标签:Spring,Component,Bean,ComponentScan,学习,bean,Configuration
From: https://www.cnblogs.com/bredy/p/18070636

相关文章

  • 6-springs_and_springlike_things
    Oneofthemostusefulforceswecancreateforourengineisaspringforce.Althoughspringshaveanobvioususeindrivinggames(forsimulatingthesuspensionofacar),theycomeintotheirowninrepresentingsoftordeformableobjectsofmanykinds......
  • Spring Boot 2.x中配置文件加载顺序分析
    一般springboot2.x的配置有多种方式,如resources文件夹中可以定义bootstrap.yml(或bootstrap.properties)、application.yml(或application.properties)、配置中心(如nacos),那么它们加载顺序是怎样的,如何使用?bootstrap.yml:首先加载bootstrap.yml(或bootstrap.properties)。这个......
  • SpringMVC拦截器
    SpringMVC拦截器拦截器介绍拦截器同过滤器一样,都是面向切面编程—AOP的具体实现,符合横切关注点的功能都可以考虑使用AOP实现;可以使用Interceptor来执行某些任务,例如在Controller处理请求之前编写日志,添加或配置更新配置;在Spring中,当请求发送到Controller处理之前,他必......
  • springboot/java/php/node/python企业微培训小程序【计算机毕设】
    本系统(程序+源码)带文档lw万字以上  文末可领取本课题的JAVA源码参考系统程序文件列表系统的选题背景和意义选题背景:随着科技的迅猛发展,移动互联网已成为企业培训的新阵地。传统的面对面培训模式因其时间、地点的限制性逐渐显得不够灵活,而小程序作为一种轻量级的应用,能够......
  • springboot的代理模式示例----面向切面编程
    1.定义切面类 2.编写切面类importcom.alibaba.fastjson.JSON;importcom.fasterxml.jackson.databind.ObjectMapper;importcom.xlkh.bigscreen.common.utils.RedisDeviceUtil;importcom.xlkh.bigscreen.service.bigscreen.BigscreenRedisService;importcom.xlkh.bigs......
  • 数据结构与算法学习(01)交换函数的指针陷阱
    先看以下正确的例子 voidswap(int*px,int*py){inttemp;temp=*px;/*间接取*/*px=*py; /*间接取,间接存*/*py=temp; /*间接存*/}int main(void){inta=2,b=3;swap(&a,&b);printf("a=%d,b=%d",a,b);return......
  • 黑马程序员JavaWeb(2023)课程学习过程中会遇到的操作小问题
    问题一:根据视频创建好的vue项目框架,在下次打开该项目时,在左下角未显示"EMP脚本",此时解决办法如下解决方法1:首先检查下图所示指向位置是否打勾(点击资源管理器右侧的三点),若没有勾上,勾上后即可看到左下角出现"EMP脚本"解决方法2:点击一下项目里面的package.json(如下图),即可解决......
  • Linux学习(十二)基础服务_DNS
    一、DNS原理查询方式递归查询直接把结果给客户端迭代查询如果知道结果,把结果告诉客户端,如果不知道结果,会把查询转发到下一台DNS服务器DNS解析类型SOA记录:起始授权记录  NS记录:指定管理某一个域的服务器是谁子域授权  A记录:正向解析,把域名解析......
  • Android Studio开发学习(一)———下载安装
    AndroidStudio版本:android-studio-2023.2.1.23-windows安装AndroidStudio官网下载   androidstudio官网安装AndroidStudio在安装目标盘创建文件夹,不要有中文文件夹,文件夹名称不要带空格。本次安装在VMware虚拟机中安装,只有一个C盘,无其他盘,所以自定义安装目录都在C......
  • springmvc入门登录功能
    学习springmvc的时候的一个入门功能,登录功能。配置好web框架,导入需要springjar包和springmvc需要的两个jar包,就可以编码了,首先写了登录需要的jsp页面<%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head><title>Title</title></hea......