Spring IOC基于XML配置使用

Spring IoC配置(xml+注解) 0.配置思路文末有本篇文章的项目源代码可供下载学习此时XML文件相当于一个向导,告诉Spring IoC容器,你不要来我这找各个组件类的配置信息了,你去哪哪哪包下去找吧,那里会标注特定的注解,你看到特定注解就会知道怎么配置各个组件类的信息了.特定注解>>>0.配置思路1.配置pom.xml。 阅读详情

一、springIOC简介

ApplicationContext是Spring IoC容器实现的代表,它负责实例化,配置和组装Bean

二、环境准备

  1. 创建maven项目
  2. 添加依赖
		<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
  1. 创建实体类
public class Student{
    private String name;
    private int age;
    private String hobby;
}
public class Person {
    private int id;
    private String realName;
    private String name;
    private Student student;
    private Date birthday;
    private List<String> hobbies;
    private Map<String,String> course;
}
  1. 在resources文件下创建XML文件springTest.xml

三、实例解析

1.实现依赖注入的两种方式

  • 基于set方法进行依赖注入
    1.注入的属性需添加set方法
    2.name值时set方法名字来的
	<bean class="com.tedu.liyu.entry.Student" id="student">
        <property name="age" value="12"></property>
        <property name="hobby" value="王者荣耀"></property>
        <property name="name" value="李白"></property>
    </bean>

创建测试类:

public class TestIOC {
    ClassPathXmlApplicationContext ioc;
    @Before
    public void before(){
        ioc = new ClassPathXmlApplicationContext("springTest.xml");
    }
    @Test
    public void test1(){
        Student student = ioc.getBean("student",Student.class);
        System.out.println(student);
    }
}
  • 基于构造函数的依赖注入
    1.注入的实体类需添加有参的构造方法
    2.name值为构造方法的入参变量
public Student(String name, int age, String hobby) {
        this.name = name;
        this.age = age;
        this.hobby = hobby;
}
	<bean class="com.tedu.liyu.entry.Student" id="student">
        <constructor-arg name="name" value="十三中"></constructor-arg>
        <constructor-arg name="age" value="18"></constructor-arg>
        <constructor-arg name="hobby" value="数学"></constructor-arg>
    </bean>

2.复杂类型的注入

下面采用的是set注入,所以实体类中需要添加相关的set方法

<bean class="com.tedu.liyu.entry.Person" id="person">
        <property name="id" value="1"></property>
        <property name="name">
            <null></null>
        </property>
        <property name="realName" value=""></property>
        <property name="birthday" value="2020/05/20"></property>
        <property name="student">
            <bean class="com.tedu.liyu.entry.Student">
                <property name="name" value="张三"></property>
                <property name="hobby" value="打篮球"></property>
                <property name="age" value="18"></property>
            </bean>
        </property>
        <property name="hobbies">
            <list>
                <value>唱歌</value>
                <value>跳舞</value>
            </list>
        </property>
        <property name="course">
            <map>
                <entry key="1" value="Java"></entry>
                <entry key="2" value="Js"></entry>
            </map>
        </property>
</bean>

3.自动注入

<bean class="com.tedu.liyu.entry.Student" id="student">
        <constructor-arg name="name" value="十三中"></constructor-arg>
        <constructor-arg name="age" value="18"></constructor-arg>
        <constructor-arg name="hobby" value="数学"></constructor-arg>
</bean>
<bean class="com.tedu.liyu.entry.Person" id="person2" autowire="byName">
        <property name="id" value="999"></property>
        <property name="name" value="666"></property>
</bean>

当person对象中需要引用另一个student对象时,在自动注入时,spring会在IOC容器中自动找到匹配的进行注入。
byName:按照名字进行装配,以属性名作为id去容器中查找组件,进行赋值,如果找不到则装配null
byType:按照类型进行装配,以属性的类型作为查找依据去容器中找到这个组件,如果有多个类型相同的bean对象,那么会报异常,如果找不到则装配null

4.Bean的作用域

singleton:单例,只会在IOC容器中创建一次
prototype:多例,每次获取IOC容器都会new一个bean

<bean class="com.tedu.liyu.entry.Student" id="student3" scope="singleton">
</bean>

5.生命周期回调

两种方式:
1.使用接口实现的方式实现生命周期的回调初始化方法:
实现接口InitializingBean,重afterPropertiesSet方法销毁方法:
实现接口DisposableBean,重写destroy方法

<bean class="com.tedu.liyu.entry.Student" id="student"></bean>
public class Student implements InitializingBean , DisposableBean {
	public void afterPropertiesSet() throws Exception {
        System.out.println("生命周期回调---初始化");
    }
    public void destroy() throws Exception {
        System.out.println("生命周期回调---销毁");
    }
}

2.使用对应bean里创建的方法实现生命周期的回调

<bean class="com.tedu.liyu.entry.Student" id="student" init-method="init" destroy-method="destroy"></bean>
public class Student{
	public void init(){
        System.out.println("生命周期回调---初始化");
    }
    public void destroy(){
        System.out.println("生命周期回调---销毁");
    }
}

示例如上:init-method的值为实体类中自定义初始化的方法名,destroy-method的值为实体类中自定义销毁的方法名

6.懒加载

<!-- 懒加载
        使用lazy‐init设置懒加载
        默认false:在spring容器创建时加载
        true:在使用时,才会加载-->
<bean class="com.tedu.liyu.entry.Student" id="student" lazy-init="false"></bean>

7.加载外部配置文件

1.先在resources下添加springContext.properties配置文件

student.name=123
student.age=10
student.hobby=中国
<context:property-placeholder location="springContext.properties" file-encoding="UTF-8"/>
<bean class="com.tedu.liyu.entry.Student" id="student">
     <property name="name" value="${student.name}"></property>
     <property name="age" value="${student.age}"></property>
     <property name="hobby" value="${student.hobby}"></property>
</bean>

示例如上:需要注意的是,需要添加file-encoding=“UTF-8”,不然配置文件中有中文时,引用可能会乱码。

8.SpEL的使用

<bean class="com.tedu.liyu.entry.Student" id="student">
        <constructor-arg name="name" value="十三中"></constructor-arg>
        <constructor-arg name="age" value="18"></constructor-arg>
        <constructor-arg name="hobby" value="数学"></constructor-arg>
</bean>
<bean class="com.tedu.liyu.entry.Person" id="person">
        <property name="name" value="#{student.name}"></property>
        <property name="student" value="#{student}"></property>
        <property name="birthday" value="2020/05/20"></property>
</bean>

SpEL:Spring Expression Language,spring的表达式语言,支持运行时查询操作对象

Spring 管理 Bean - IOC (基于 XML 配置 Bean) IOC(Inversion of Control)即“控制反转”,是 Spring 框架的核心之一。在传统的编程中,开发者自己负责对象的创建和管理。使用 IOC 后,Spring 容器负责创建和管理对象,并在需要时将所依赖的对象注入到 Bean 中,减少了手动管理对象的复杂性。我们需要创建与 XML 配置文件中定义的 Bean 对应的 Java 类。这些类会被 Spring 容器管理。return age;// 打印信息的方法// 打印地址的方法。 阅读详情

相关推荐

电力电子技术文章:ACOT控制模式在Buck变换器中的频率稳定性分析

本文深入分析了ACOT控制模式在Buck变换器中实现频率稳定性的原理与优势。通过对比传统COT模式,阐述了ACOT如何通过自适应调整导通时间,将开关频率锁定在设定值,从而有效应对输入电压与负载变化。文章还探讨了其在轻载DCM模式下的高效与平滑切换特性,并提供了关键的设计考量与实战指南。

cc789的博客 1149

Spring基于xml配置使用IOC

Spring基于xml配置的IOC

怪咖@的博客 1357

Qt开发实战:QWebEngineView缓存路径详解与自定义配置(Windows/Linux)

本文详细解析了Qt框架中QWebEngineView组件的缓存机制,提供了Windows和Linux系统下的默认缓存路径及自定义配置方案。通过实战代码示例,展示了如何实现跨平台缓存路径管理、权限设置以及企业级应用中的多用户隔离策略,帮助开发者有效管理Web内容缓存,提升应用性能和数据安全性。

weixin_42519826的博客 403

Spring IOC基础 xml配置、注解配置

依赖注入:Dependency Injection IOC的作用:降低程序间的耦合(依赖关系) 依赖关系的管理:交给spring管理 1.使用xml配置 1.1 ApplicationContext与BeanFactory 对两个文件:AccountServiceImpl、AccountDaoImpl进行注入 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/

weixin_43838446的博客 293

基于OpenAI Agents构建多智能体工作流:从原理到实战

多智能体系统(Multi-Agent System)是人工智能领域的重要分支,它通过多个智能体(Agent)的协作与交互,解决单一智能体难以处理的复杂任务。其核心原理在于将任务分解、分配与协调,每个智能体具备特定能力,通过通信机制实现信息共享与决策协同。在工程实践中,多智能体框架的价值在于提升任务处理效率、增强系统鲁棒性,并支持模块化开发。典型的应用场景包括自动化工作流编排、复杂问题求解以及人机协同交互。本文以OpenAI Agents SDK为例,深入探讨如何利用其提供的智能体(Agent)、会话(Ses

weixin_28725959的博客 603

Lumerical 教程目录,说明及个人感悟(共计138篇,持续更新中)

Lumerical---教程说明及个人感悟

u011699626的博客 1万+

Spring-IOC-XML配置

Ioc是什么 IOC(inversion of control)控制反转,Spring反向控制应用程序所需要的外部资源,将控制的外部资源都放在spring容器中(ioc容器),开发者可以不用去管对象的创建和释放,全部都由spring代为完成。由我们之前主动去创建资源变为被动的由spring分配资源 简单的入门案例 第一步 配置spring的maven坐标 <dependencies> <dependency> <groupI..

Promise_J_Z 1497

LVGL 磁罗盘效果

环境:LVGL 9.x + SDL2,窗口 1280×800。界面文案用英文(默认 Montserrat,无 CJK)。本文按实现顺序讲:先建立两个耦合转动体,再把磁倾角误差从卡面倾斜里推出来,最后用同一套投影把刻度、数字和目标画到卡上。画面上的迟滞、涡流、摆动和读数偏差都来自方程,没有补间动画。

摸鱼专家 85

Spring_Ioc基本配置使用(基于xml)

Spring_Ioc1、IOC简介1.1、什么是IOC2、容器2.1、容器概述 1、IOC简介 1.1、什么是IOC IOC是Inversion of Control的缩写,多数书籍翻译成“控制反转”。 是Spring框架里面管理对象的一个容器。 2、容器 2.1、容器概述 ApplicationContext是Spring容器IOC实现的代表,它负责实例化、配置和组装Bean。容器通过读取配置元数据获取有关实例化、配置和组装哪些对象的说明。配置元数据可以使用xml、Java注解活Java代码来呈现,它允许

qq_41931364的博客 744

GEE 案例分析:利用Landsat数据进行FAI、NDVI及CHLA分析并统计平均值(巢湖为例)

浮游藻类指数(FAI)、归一化植被指数(NDVI)及叶绿素a(CHLA)是水体环境监测的重要指标。本文利用Google Earth Engine(GEE)平台,基于Landsat 5和Landsat 8数据,进行水体藻类及植被监测。

此星光明博客 1336

ios开发拒绝“玄学”Crash:从循环引用到脏内存,构建你的系统性排查思维模型

你申请了内存,写了数据,这块内存就是脏的。系统无法直接回收它,除非你显式释放,或者系统把它 swap 出去(但在 iOS 上,Compressed Memory 机制虽然能压缩,但不会像桌面系统那样频繁 swap 到磁盘,一旦压缩内存也撑不住,你也得挂)。所以,排查 OOM 的核心心法只有一条:不要问“哪里漏了”,要问“每一刻,留在这个页面上的内存,凭什么必须在这里?一旦内存水位线逼近阈值(不同机型不同,老机器可能 600MB 就危,新机器能抗 1.5GB),系统发个警告。

大模型大数据攻城狮的专栏 724

Spring之IOC及XML配置方式

IOC(Inversion of Control)控制反转 控制反转就是对对象的控制权转移,从程序代码本身反转到了外部容器。把对象的创建、初始化、销毁等工作交给spring容器来做。由spring容器控制对象的生命周期。Spring 容器使用依赖注入(DI)来管理组成一个应用程序的组件。这些对象被称为 Spring Beans 通过阅读配置元数据提供的指令,容器知道对哪些对象进行实例化,配置和组装...

zhouym_的博客 1449

ModuleNotFoundError: No module named‘langchain.schema.output parserlangchain.schema is not a package

电脑里现有的langchain库版本与import所需的不同,卸载原有langchain,重新下载最新的langchain。在步骤1后,若仍不可运行。在确保已重新下载新langchain后,重启python后,可正常运行。在版本号中填入所需的langchain版本号,可在requirements.txt查看。运行如下代码时,出现error。

weixin_45751925的博客 1713

【spring01】Spring 管理 Bean-IOC,基于 XML 配置 bean

Spring 最大的价值,通过配置,给程序提供需要使用的web 层

qq_74232707的博客 2658

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 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 IoC 基于XML配置方式组件管理

组件可以完全交给Spring 框架进行管理,Spring框架替代了程序员原有的new对象和对象属性赋值动作等!我们只需要编写元数据(配置文件)告知Spring 管理哪些类组件和他们的关系即可。组件是对象,对象不一定是组件。简单说,组件就是可复用的Java对象综上所述,Spring 充当一个组件容器,创建、管理、存储组件,使得可以通过配置的方式使用或改造组件,减少了我们的编码压力,让我们更加专注进行业务编写!

m0_46565230的博客 1950

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【spring】 基于XML的IOC配置

spring 基于XML的IOC配置 bean.xml <!-- 配置Service --> <bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl"> <!-- 注入dao --> <property name="a...

ShiJ的博客 139

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Spring-IOC的XML配置

引言 在Springboot编程实践中,我们偏向使用注解的方式进行Bean的注册和依赖注入等,但XML格式的容器信息管理方式仍是Spring提供的最为强大、支持最为全面的方式,本文对Spring-IOC的XML配置进行详细的讲解。 <beans>和<bean> BeanFactory和ApplicationContext的XML配置均采用统一的格式,在Spring2.0之前...

打酱油的葫芦娃 5365

细说Spring——IoC详解(XML配置一)

在我们经过了: 细说Spring——IoC详解(一) 细说Spring——IoC详解(二) 细说Spring——IoC详解(三) 的学习之后,已经对Spring的Ioc容器有了一定的了解,我们队容器如何创建对象有了细致的了解,接下来就是一些其他零零散散的东西,这一期就主要讲解Spring IoC容器的XML配置文件。 一、我们应该怎么理解和认识Spring的配置文件呢? 其实,Sp...

啦啦啦的博客 4136

Spring使用XML文件配置IOC

spring是一个开发框架 一般Java应用都会用得到spring spring量大特性IOC,AOP 特点就很强大,能简化开发流程 使用spring第一件事,引包 在pom(service)中引入 <dependency> <groupId>org.springframework.boot</groupId> &...

qq_41767337的博客 1293

Spring之IOC的xml配置与注解配置

spring是一个开源的Java开发框架。其核心为IOC与AOP。spring的IOC控制反转就是将对象的创建与对象之间依赖关系的维护交给spring容器进行管理,而spring如何管理对象,则通过下面两种方式。

m0_64926208的博客 1022

Spring-IOC-XML配置方式

Spring-IOC-XML配置方式导入jar包项目目录项目代码配置文件xmlJava代码接口实现类测试类结果 导入jar包 4+1:4个核心+1个依赖 Beans:spring-beans-5.2.3.RELEASE.jar Core:spring-core-5.2.3.RELEASE.jar Context:spring-context-5.2.3.RELEASE.jar SpEL:spring-expression-5.2.3.RELEASE.jar commons-loggins:commons

张子布 713

01Spring基于xml的IOC配置--入门

01Spring基于xml的IOC配置 1、创建一个普通的maven工程 1.1 选择maven,不用骨架,点击下一步。 1.2 填写GroupId、ArtifactId、Version。填完点击下一步 1.3 确认项目路径,确认完成点击finish 2、模拟三层创建包和类 2.1 创建service接口 package com.yu...

aikeng3494的博客 195

Java Spring IOC的xml配置

Java Spring IOC的xml配置 一、案例 利用xml配置 连接数据库增删改查 1.1、类包目录 1.2案例准备 导包 pom.xml ··· <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.springframework</groupId>

h15835161250的博客 234

Spring IoC基于XML的DI详细配置全解【两万字】

详细介绍了Spring IoC基于XML的DI详细配置全解。

终生学习践行者 2408

实验四 Spring IoC-xml配置

在testàjava包下新建包sdjzu.springIoc,在该包下新建类TestIoC.java。,在该包下新建接口IPerson.java、IAxe.java和类Chinese.java、American.java、SteelAxe.java、Stone.java。System.out.println("软件211朱晓辉"+"steelAxe is blunt!System.out.println("软件211朱晓辉"+"stoneAxe is shark!(1)在testàjava包下新建包。

2401_83632313的博客 792

Spring的ioc的xml配置

Spring的IOC的xml配置 * 获取spring的ioc核心容器,并根据id获取对象 * ApplicationContext的三个常用实现类 * ClassPathXmlApplicationContext * 它可以加载类路径下的配置文件,要求配置文件必须在类路径下,不在的话,加载不了 * FileSystemXmlApplicationContext ...

weixin_42947972的博客 170
上一篇: 深入理解mysql的MVCC机制及实例详解
下一篇: Spring IOC基于注解和XML配置使用
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值