Spring工程搭建
创建Maven项目
1.下载Maven资源包
http://maven.apache.org/download.cgi
2.打开IDEA创建Maven项目
在新建项目窗口选择Maven项目:检查当前SDK版本是否为最新版本。
配置Maven
1.修改Maven home directory的路径
- File——Settings...打开设置
- 搜索Maven
- 改路径
搭建配置引入依赖:
- Maven仓库查询链接:mvnrepository
<dependencies>
<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>
</dependencies>
刷新Maven
代码截屏:
1.接口类
2.实现类
3.实现接口
4.测试类的方法
5.测试结果
步骤:
1、新建UserService接口
2、新建UserService实现类
3、通过bean将UserService放入容器
4、通过context的getbean方法拿到UserService对象