spring-framework源码加载与测试
源码
Gradle(类似maven,ant)Build Tool
install Gradle
open spring-framework
编译
依次找到spring-core,spring-oxm,spring-context,spring-beans,spring-aspects,spring-aop对应如图compileTestJava,并双击执行完成编译,可能中间会存在一些编码之类的warning可以先pass
add module
- 选择Gradle-Java,next,finish
修改build.gradle
添加POJO、XML
- POJO
public class Doimyakon {
private String username;
private String password;
}
- XML
<?xml version="1.0" encoding="UTF-8"?>
<!--根标签beans,里面配置一个又一个的bean子标签,每一个bean子标签都代表一个类的配置-->
<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
https://www.springframework.org/schema/tx/spring-tx.xsd "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns="http://www.springframework.org/schema/beans">
<bean id="doimyakon" class="Doimyakon"></bean>
</beans>
- Test
public class IocTest {
@Test
public void testIoc(){
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Doimyakon doimyakon = applicationContext.getBean(Doimyakon.class);
System.out.println(doimyakon);
}
}
- 运行