XML-Based Injection in Spring 基于XML配置的依赖注入

原文链接:XML-Based Injection in Spring 

1. Introduction 概述

In this basic tutorial, we’ll learn how to do simple XML-based bean configuration with the Spring Framework.

这里,一起学习如何在Spring框架中使用XML文件进行bean对象配置吧

 

2. Overview 回顾一下

Let's start by adding Spring's library dependency in the pom.xml:

首先在pom.xml文件中添加Spring上下文的依赖

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.1.4.RELEASE</version>         
</dependency>

 

3. Dependency Injection – an Overview 复习下依赖注入

Dependency injection is a technique whereby dependencies of an object are supplied by external containers.

依赖注入是一种技术理念,通过一个外部容器来提供某个对象所需要的所有依赖。

Let's say we've got an application class that depends on a service that actually handles the business logic:

让我们来假设,已经有一个程序类,它依赖了一个service来真正的处理业务逻辑,如下:

public class IndexApp {
    private IService service;
    // standard constructors/getters/setters
}
<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值