Java框架_Spring5_day05_IOC(注解)

京淘实训Day05-SpringBoot加强 SpringBoot入门 阅读详情

目录

七、使用注解去掉 applicationContext.xml 中的所有配置

7.1 @Configuration

7.2 @ComponentScan 

7.3 @Bean

7.4 工厂AnnotationConfigApplicationContext.java

7.5 @Import

7.6 @PropertySource

7.7 @Qualifier

八、使用 Spring 整合 Junit

8.1 导入 Spring 整合 Junit 的坐标

8.2 测试类


七、使用注解去掉 applicationContext.xml 中的所有配置

7.1 @Configuration

@Configuration
public class SpringConfiguration {

}

       表示该类是一个配置类,它的作用和applicationContext.xml是一样的我们下面讲解的是spring5中的新注解

@Configuration​

       作用:指定当前类是一个配置类,如同取代applicationContext.xml中的配置​

       细节:当配置类作为AnnotationConfigApplicationContext对象创建时,该注解可以不写

7.2 @ComponentScan 

@ComponentScan​

       作用:用于通过注解指定spring在创建容器时要扫描的包​

       属性:​ value:它和basePackages的作用是一样的,都是用于指定创建容器时要扫描的包的范围。

@Configuration
@ComponentScan(value = {"com.cpz"})
public class SpringConfiguration {

}

上述代码相当于 xml 中配置的:

<context:component-scan base-package="com.cpz"></context:component-scan>

7.3 @Bean

@Bean​

       作用:用于把当前方法的返回值作为bean对象存入spring的ioc容器中

       属性:name:用于指定bean的id。当不写时,默认值是当前方法的名称​

       细节:我们使用注解配置方法时,如果方法有参数,spring框架会去容器中查找有没有可用的bean对象,如果有bean对象,将对象通过方法的形参注入到方法中使用。查找的方式和Autowired注解的作用是一样的。

@Configuration
@ComponentScan(value = {"com.cpz"})
public class SpringConfiguration {

    /**
     * 用于创建一个QueryRunner对象
     * @param dataSource
     * @return
     */
    @Bean(name="queryRunner")
    @Scope("prototype")
    public QueryRunner createQueryRunner(DataSource dataSource){
        return new QueryRunner(dataSource);
    }

    /**
     * 创建数据源对象
     * @return
     */
    @Bean(name="dataSource")
    public DataSource createDataSource(){
        try {
            ComboPooledDataSource dataSource = new ComboPooledDataSource();
            ds.setDriverClass("com.mysql.jdbc.Driver");
            ds.setJdbcUrl("jdbc:mysql://localhost:3306/spring");
            ds.setUser("root");
            ds.setPassword("1234");
            return dataSource;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}

7.4 工厂AnnotationConfigApplicationContext.java

       当配置类作为AnnotationConfigApplicationContext对象创建的参数时,@Configuration注解可以不写。

public class SpringTest {

    @Test
    public void testFindAll() {
        // 这里要使用 AnnotationConfigApplicationContext 实现类
        ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfiguration.class);
        AccountService accountService = ac.getBean("accountService",AccuntService.class);
        //3.执行方法
        List<Account> list= as.findAcountAll();
        for(Account account : list){
            System.out.println(account);
        }
    }
}

7.5 @Import

@Import​

       作用:用于导入其他的配置类​ 属性:

       value:用于指定其他配置类的字节码。

当我们使用Import的注解之后,有Import注解的类就父配置类,而导入的都是子配置类,相当于applicationContext.xml中的<import resource=””>

首先我们将配置都放到 JdbcConfig.java 配置类中,然后在 SpringConfiguration.java 中引入 JdbcConfig.java 的配置

//@Configuration
@ComponentScan(value = {"com.cpz"})
@Import(value= JdbcConfig.class)
public class SpringConfiguration {

}

7.6 @PropertySource

@PropertySource​

       作用:用于指定properties文件的位置​

       属性:​ value:指定文件的名称和路径。​

       关键字:classpath,表示类路径下

//@Configuration
@ComponentScan(value = {"com.cpz"})
@Import(value= JdbcConfig.class)
@PropertySource("classpath:jdbc.properties")
public class SpringConfiguration {

}

关联好属性文件后,我们还要配置 JdbcConfig 配置类,使得创建数据源时使用的参数来自属性文件。

public class JdbcConfig {
    @Value("${jdbc.driverClass}")
    private String driver;
    @Value("${jdbc.jdbcUrl}")
    private String url;
    @Value("${jdbc.user}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean(name = "queryRunner")
    @Scope(value = "prototype")
    public QueryRunner createQueryRunner(DataSource dataSource){
        return new QueryRunner(dataSource);
    }

    @Bean(name = "ds")
    public DataSource createDataSource(){
        try {
            ComboPooledDataSource ds = new ComboPooledDataSource();
            ds.setDriverClass(driver);
            ds.setJdbcUrl(url);
            ds.setUser(username);
            ds.setPassword(password);
            return ds;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}

7.7 @Qualifier

作用:如果spring容器中出现了多个数据源类型,使用该注解指定注入的数据源。

public class JdbcConfig {
    @Value("${jdbc.driverClass}")
    private String driver;
    @Value("${jdbc.jdbcUrl}")
    private String url;
    @Value("${jdbc.user}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean(name = "queryRunner")
    @Scope(value = "prototype")
    public QueryRunner createQueryRunner(@Qualifier(value = "dataSource1") DataSource dataSource){
        return new QueryRunner(dataSource);
    }

    @Bean(name = "dataSource1")
    public DataSource createDataSource1(){
        try {
            ComboPooledDataSource dataSource1 = new ComboPooledDataSource();
            dataSource1.setDriverClass(driver);
            dataSource1.setJdbcUrl(url);
            dataSource1.setUser(username);
            dataSource1.setPassword(password);
            return dataSource1;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    @Bean(name = "dataSource2")
    public DataSource createDataSource2(){
        try {
            ComboPooledDataSource dataSource2 = new ComboPooledDataSource();
            dataSource2.setDriverClass(driver);
            dataSource2.setJdbcUrl(url);
            dataSource2.setUser(username);
            dataSource2.setPassword(password);
            return dataSource2;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}

八、使用 Spring 整合 Junit

8.1 导入 Spring 整合 Junit 的坐标

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>

8.2 测试类

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfiguration.class)
public class SpringTest {

    @Autowired
    AccountService accountService;

    @Test
    public void findAll(){
        List<Account> list = accountService.findAccountAll();
        for (Account account : list) {
            System.out.println(account);
        }
    }
}

总结:

@Runwith(加载 SpringJUnit4ClassRunner.class )

       使用Junit提供的一个注解把原有的main方法替换了,替换成spring提供的

@ContextConfiguration

       告知spring的运行器,spring和ioc创建是基于xml还是基于注解的,并且说明位置

        locations:指定xml文件的位置,加上classpath关键字,表示在类路径下

                @ContextConfiguration(locations = "classpath:applicationContext.xml")
        classes:指定注解类所在地位置

                @ContextConfiguration(classes = SpringConfiguration.class)   

注意:当我们使用spring 5.x版本的时候,要求junit的jar必须是4.12及以上

华为AR6140E/S5735设备密码策略配置全攻略:从复杂度到锁定机制 本文详细介绍了华为AR6140E/S5735设备的密码策略配置方法,涵盖密码复杂度、时效性和防护性三大核心维度。通过具体的CLI命令示例,指导管理员如何设置密码长度、字符组合、有效期及登录失败锁定等安全机制,为企业网络提供全面的用户名密码防护策略。 阅读详情

相关推荐

(超详细)Scala环境搭建(scala-2.12.15、IDEA2021.1.3)

Scala环境搭建(scala-2.12.15、IDEA2021.1.3) JunLeon——go big or go home 目录 Scala环境搭建(scala-2.12.15、IDEA2021.1.3) 一、Scala概述 1、什么是Scala? 2、Scala发展史 3、Scala与Java的关系 二、Scala环境搭建 1、环境准备 2、Scala安装与配置环境变量 3、验证Scala 三、编写第一个Scala程序 1、使用IDEA创建maven工程 2、.

JunLeon的博客 3万+

Spring5详解

Spring5详解 文章目录Spring5详解概念Spring的特点1、轻量级2、控制反转3、面向切面4、容器5、框架Spring的优势1、方便解耦,简化开发2、AOP 编程的支持3、声明式事务的支持4、方便程序的测试5、方便集成各种优秀框架6、Java 源码是经典学习范例Spring 的体系结构Spring中的常用注解Spring IOC1、概念2、spring 中工厂的类结构图1、BeanFactory 和 ApplicationContext 的区别2、IOC 中 bean 标签和管理对象细节1、be

qq_45592174的博客 7035

新手必看:如何用Python模拟电动助力转向系统(EPS)的传感器信号处理

本文详细介绍了如何使用Python模拟电动助力转向系统(EPS)的传感器信号处理流程,包括转向力矩、转向角度和车速信号的生成与滤波处理。通过实战代码示例,帮助开发者理解ECU如何计算助力扭矩,并提供了可视化分析和性能优化建议,适合汽车电子系统开发新手学习。

weixin_28327051的博客 354

《Spring 5 官方文档》1. Spring入门指南

1.Spring入门指南本参考指南提供了有关Spring Framework的详细信息。它全面的介绍了Spring的所有的功能,以及Spring涉及的基础概念(如“依赖注...

ifeves的博客 2255

时间同步中 TOD 与GPRMC和IRIG-B的区别

时间同步中 TOD 与GPRMC和IRIG-B的区别

ftdlk的博客 1726

【git】git: ‘interpret-trailers’ is not a git command. See ‘git --help’

cents 7.6系统. yum源安装git最新版本是1.8.3 报错: git: 'interpret-trailers' is not a git command. See 'git --help'. cannot insert change-id line in .git/COMMIT_EDITMSG 解决: git add xxx git commit -m "xxx" 然后修改 vim .git/hooks/commit-msg #if test -n "${reviewurl}" ; th

machh的专栏 4758

spring5新特性

走过路过不要错过点击蓝字关注我们前方:对于很多开发人员来说,目前大都还在使用spring4的时候,而spring5早已经发布。虽然你可能暂时还没有使用到spring5,但还是需要对其有个...

Java烂猪皮 812

FreeRTOS全攻略:从入门到精通

本文聚焦 FreeRTOS,从基础概念出发,阐述其开源、轻量级等优势。着重介绍 FreeRTOS 入门知识,涵盖内存管理、任务操作、同步互斥机制等核心内容。其中,空闲任务与钩子函数保障系统基础运行与功能扩展;队列、信号量、互斥锁和事件组等机制,分别从数据传递、资源访问控制、优先级问题解决及多任务同步等方面,为开发者提供高效的任务间协作与资源管理方案,助力开发者掌握 FreeRTOS 核心技术,为嵌入式项目开发筑牢基础。

邓邓子的博客 6358

java学习之Spring5

Spring51.Spring5框架概述 1.Spring5框架概述

qq_28356977的博客 985

UniApp 覆盖安装后首次进入 APP pages.json 不生效的解决方案

通过以上步骤,解决了缓存问题导致的首次加载异常。此方案的关键在于强制更新文件名,从根本上避免旧缓存的干扰。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 683

CVPR 2026 即插即用 | 注意力篇 | MSEF:超轻注意力,空间-通道双分支并行融合,既增强特征又抑制噪声!

Multinex提出了一种超轻量级微光图像增强框架,其核心创新是MSEF模块。MSEF采用双分支并行架构,结合空间局部特征(深度可分离卷积)和全局通道注意力(改进SE),通过Tanh激活实现特征增强与抑制。相比传统注意力模块,MSEF在几乎不增加计算量的情况下显著提升性能,特别适合轻量级网络和边缘设备部署。实验表明,该模块能有效提升PSNR约3dB,同时保持极低的参数量(0.7K-45K)。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 604

Java总结:Spring5框架(1)

Spring5框架(1) 一:什么是Spring? Spring框架是由于软件开发的复杂性而创建的。Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅仅限于服务器端的开发。从简单性、可测试性和松耦合性角度而言,绝大部分Java应用都可以从Spring中受益。 ◆目的:解决企业应用开发的复杂性 ◆功能:使用基本的...

岁月求索 922

【PPS便携式移动电源】如何透彻了解便携式移动电源,仅需要十分钟阅读即可

PPS 便携式储能电源的发展前景广阔,受益于户外经济爆发、应急备灾需求提升及 “双碳” 政策支持,全球市场规模预计持续增长,2025 年出货量将达 2380 万台,未来将向大功率大容量、光充一体化、智能化方向发展,还会拓展家庭储能、移动医疗等新场景,同时钠离子电池应用、双向逆变技术升级将进一步推动行业发展。

昔时扬尘处 272

Spring-学习笔记05【基于XML的IOC的案例】

Spring-学习笔记05【基于XML的IOC的案例】

upward 1186

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

day05 java_Spring IoC 和 DI

1.以后所有创建对象的操作全部交给spring的xml文件来做2.使用bean注入的时候使用时property标签中的ref属性3.spring创建对象的时候使用的实现类进行创建4.创建对象的时候需要在类里面设置setter方法,spring才能使用反射进行属性的获取,并给这个对象赋值5.连接数据库的时候需要添加配置文件,给配置文件中的key设置名字,防止spring读取的时候读到最大的权限### 总结**1.以后所有创建对象的操作全部交给spring的xml文件来做**

jgxc152的博客 1013

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Spring-学习笔记06【Spring的新注解】

Spring-学习笔记06【Spring的新注解】

upward 557

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring-学习笔记01【Spring框架简介】

Spring-学习笔记01【Spring框架简介】

upward 633

8.05 Day36----Spring两大核心模块

IOC&DI Inversion Of Control 控制反转(在运行时基于反射发现组件类和注册对象的过程) Dependency Injection 依赖注入(赋值的工程) 具有IoC功能的注解: 什么控制权? 为什么要反转? Component组件(组成工程的原件,指的是类) Bean/JavaBean 咖啡豆/组成(指的对象/被IoC容器发现后创建的对象) IoC&DI的实现方式有3种: 日志管理: 打印日志的规则: 日志级别: 设置日志规则: AOP: 建aop的依..

qq_63771774的博客 265

每周小记——Spring框架

本文解析了Spring框架的四大核心机制:工厂模式通过BeanFactory和ApplicationContext实现Bean生命周期管理,奠定IoC容器基础;控制反转与依赖注入将对象创建权移交容器,通过配置解耦组件,提升系统灵活性;面向切面编程基于代理模式(静态/JDK动态/CGLIB)实现横切关注点(如日志、事务)与业务逻辑分离,并总结了五种通知类型及其配置方法。文章系统阐述了Spring如何通过设计模式优化Java企业级开发,强化代码可维护性与模块化,凸显其在现代架构中的关键作用

weixin_57655687的博客 1553

Java学习Day16

10.如果在 <bean> 中指定了该 Bean 的作用范围为 scope="singleton",则将该 Bean 放入 Spring IoC 的缓存池中,将触发 Spring 对该 Bean 的生命周期管理;如果在 <bean> 中指定了该 Bean 的作用范围为 scope="prototype",则将该 Bean 交给调用者,调用者管理该 Bean 的生命周期,Spring 不再管理该 Bean。DI 的基本思想是将对象的创建和管理职责从客户端代码转移到外部容器或框架中,从而解耦对象之间的关系。

m0_63651681的博客 639

java-spring-boot

day01、spring-Ioc 01、Spring课程导入 一个service接口调用不同的实现类的方法,需要指定不同的实现类****,存在耦合问题,**** 02、Spring简介 Spring 是一款目前主流的 Java EE ==轻量级、全栈型 开源框架== ,是 Java 世界最为成功的框架之一。 Spring 由“Spring 之父”Rod Johnson 提出并创立,其目的是用于简化 Java 企业级应用的开发难度和开发周期。 自 ==2004== 年 4 月,Spring 1.0 版

weixin_51480322的博客 869

day05-SpringBootWeb请求响应

在上一次的课程中,我们开发了springbootweb的入门程序。基于SpringBoot的方式开发一个web应用,浏览器发起请求 /hello 后 ,给浏览器返回字符串 “Hello World ~”。其实呢,是我们在浏览器发起请求,请求了我们的后端web服务器(也就是内置的Tomcat)。而我们在开发web程序时呢,定义了一个控制器类Controller,请求会被部署在Tomcat中的Controller接收,然后Controller再给浏览器一个响应,响应一个字符串 “Hello World”。

qq_44428997的博客 1014

黑马程序员JavaWeb开发教程(后端部分Day04-01~Day05-13) ---笔记分享

如果不知道依赖的坐标信息,可以到中搜索HTTP协议规定了浏览器与服务器之间数据传输的规则打开startup.bat出现了打不开的情况,并不是大多数的一闪而过,查资料排查是系统环境变量配置问题。

蓝桉 1578

jy-09-SERVLETJSP——Spring-程祖红

目录: 1、day01-Spring 2、day02-IOC和DI 3、day03-使用注解来简化配置 4、day04-SpringMVC 5、day05-系统分层(扩展) 6、day06-拦截器 1、day01-Spring (1)Spring是什么? 是一个开源的,用来简化企业级应用开发的应用开发框架。 注: a. Spring框架对常用的api做了封装(比如,对jdbc就做了封装), 这样一来,会简化代码并提高代码的质量(比如,使用SpringJdbc 来访问数据库,就不..

从码农到码到成功 271

Spring-学习笔记06【spring_day02资料_dbutils】

Spring-学习笔记06【spring_day02资料_dbutils】

upward 541

IOC控制反转+依赖注入的详解+springmvc如何前后端分离并且解决乱码问题+IO流+实训+day0731

day05 IOC控制反转的思维 回顾 用配置文件代替工厂模式,其实配置文件就是一个工厂模式 任何框架的出现是简化代码,应该是越做越简单 IOC 是一个容器,装什么东西呢?装的是一堆对象,放的是一堆配置文件中配置的对象,他们装到容器中,spring自己放进IOC,我们只需要配置就好了,不需要自己去放 单元测试工具Junit,首先导包,JUntil还有导入spring-test测试包,版本号要保持一致 @RunWith("SpringJUnit4ClassRUnner.class) @COnt

老男孩的粉丝团 259
上一篇: Java框架_Spring5_day04_IOC(DBUtils)
下一篇: Java框架_Spring5_day06_转账案例(事务)
chipeize
博客等级 码龄10年 23粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值