简单的说一下spring的搭建流程,内容偏基础,底子很差的能够看一下!java
如图所示:找到以前准备好的文件路径面试
一、新建UserService接口
二、新建UserService实现类
三、经过bean将UserService放入容器
四、经过context的getbean方法拿到UserService对象spring
代码以下:express
<dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.2.13.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.2.13.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.13.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>5.2.13.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.2.13.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-jcl --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jcl</artifactId> <version>5.2.13.RELEASE</version> </dependency>
后刷新Maven.架构
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> </beans>
点右上角提示的“Configure application context”就能够了。app
编写代码学习
代码以下测试
新建class文件UserServiceImplspa
public class DemoTest { public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext ("classpath:applicationContext.xml"); UserSvice service = (UserSvice) context.getBean("userService"); service.saveUser(); } }
如图:
运行mian方法,code
在文章的最后做者为你们整理了不少资料!包括java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书等等!欢迎关注公众号:前程有光,自行下载!