首先新建一个maven项目
然后再pom.xml中导入spring所需要的依赖
<dependencies>
<!--注入spring所需要的依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
</dependencies>
随便写一个想要注入的类
把这个类交给spring.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.xsd">
<!--
一个类注入到bean时,com.service.HelloWord表示在哪个包的哪个类
而bean的id="hello"表示HelloWord中的方法hello
-->
<bean id="hello" class="com.service.HelloWord">
</bean>
</beans>
用此时类来检验自己写的类是否交给了spring管理
控制台上成功输出,表示被管理