0:准备spring的文件
spring-5.2.5.RELEASE-dist.zip
spring-5.2.5.RELEASE-docs.zip
spring-5.2.5.RELEASE-schema.zip
下载地址:
http://repo.spring.io/release/org/springframework/spring/
1:file–>close project(关闭当前项目)
2:选择maven–>next
3:创建项目
项目结构如图:
4:编写bom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mySpringStudy01</groupId>
<artifactId>springStudy01</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
</dependencies>
</project>
5:创建java类
ApplyTermsControl:
public class ApplyTermsControl {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
IApplyTermsService iApplyTermsService = (IApplyTermsService)applicationContext.getBean("applyTermsServiceImpl");
iApplyTermsService.queryApplyTermsServiceById("202004180001");
}
}
IApplyTermsService:
public interface IApplyTermsService {
void queryApplyTermsServiceById(String applySerialNo);
}
ApplyTermsServiceImpl
public class ApplyTermsServiceImpl implements IApplyTermsService {
private IApplyTermsDao iApplyTermsDao;
public ApplyTermsServiceImpl(){
}
@Autowired
public void setApplyTermsDao(IApplyTermsDao iApplyTermsDao){
this.iApplyTermsDao = iApplyTermsDao;
}
public void queryApplyTermsServiceById(String applySerialNo) {
System.out.println("this is :" + applySerialNo);
iApplyTermsDao.queryApplyTermsServiceById(applySerialNo);
}
}
IApplyTermsDao
public interface IApplyTermsDao {
void queryApplyTermsServiceById(String applySerialNo);
}
ApplyTermsDaoImpl
public class ApplyTermsDaoImpl implements IApplyTermsDao {
public void queryApplyTermsServiceById(String applySerialNo) {
System.out.println("this is ApplyTermsDaoImpl:" + applySerialNo);
}
}
6:通过xml配置的方式装载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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="applyTermsDaoImpl" class="study01.dao.impl.ApplyTermsDaoImpl"></bean>
<bean id="applyTermsServiceImpl" class="study01.service.impl.ApplyTermsServiceImpl">
<property name="applyTermsDao" ref="applyTermsDaoImpl"/>
</bean>
</beans>
xml装载bean的校验可以查看下载的源码文档:spring-5.2.5.RELEASE-dist.zip
spring-framework-5.2.5.RELEASE/docs/spring-framework-reference/index.html
直接拷贝内容: