1、在pom.xml中引入依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
</dependencies>
2、配置国内源


3、添加Spring的配置文件
在resources中new一个File:名为spring.xml(或者spring-config.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">
</beans>
4、将bean通过配置文件注册到Spring中

Spring更加简单的读取和存储对象:
1、前置条件:
在spring配置文件中设置bean的扫描跟路径
<?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:content="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<content:component-scan base-package=""></content:component-scan>
</beans>

本文档介绍了如何在Spring项目中配置pom.xml以引入Spring核心依赖,并提供了配置国内Maven源的方法。接着,展示了创建Spring配置文件spring.xml的步骤,以及如何使用component-scan注解扫描并注册bean。通过这些步骤,可以简化Spring中对象的管理和读取。
8163

被折叠的 条评论
为什么被折叠?



