IoC入门案例制作步骤:
1.导入spring坐标
2.编写业务层与表现层接口与实现类
3.建立spring配置文件
4.配置所需资源(Service)为spring控制的资源
5.表现层(APP)通过spring获取资源(Service实例)
步骤
1.加载spring
2.创建资源
3.配置资源
4.使用资源
打开 spring.io
找到官方文档的spring framework的core
随便找一个代码的开头复制
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
新建三个文件
UserService.java内容
UserServiceImpl.java内容
applicationContext.xml内容(我们从官网复制的内容)
bean的id可以随便写,建议是首字母小写,其他与接口名一致,class为实现类的目录。
新建UserApp
内容如下
运行即可查看结果