Spring Dependency Injection 简明教程
Spring Dependency Injection - Create Project
使用 Eclipse 选择 File → New * → *Maven Project 。勾选 创建简单项目(跳过原型选择),然后单击下一步。
按照以下所示输入详细信息 −
-
groupId − com.tutorialspoint
-
artifactId − springdi
-
version − 0.0.1-SNAPSHOT
-
name − springdi
-
description − Spring 依赖项注入项目
单击完成按钮,将创建一个新项目。
pom.xml
使用 Spring Core 依赖项更新 pom.xml。以下是 pom.xml 的完整内容
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tutorialspoint</groupId>
<artifactId>springdi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springdi</name>
<description>Spring Dependency Injection Project</description>
<properties>
<org.springframework.version>5.3.9</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
applicationcontext.xml
在 *src → main → resources * 中创建 applicationcontext.xml,其内容如下。
applicationcontext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</beans>