Spring入门篇 学习笔记
常用的两种注入方式
- 设值注入
- 构造注入
示例准备工作
添加 InjectionDAO:
1 | public interface InjectionDAO { |
添加 InjectionDAOImpl:
1 | public class InjectionDAOImpl implements InjectionDAO { |
添加 InjectionService:
1 | public interface InjectionService { |
设值注入
添加 InjectionServicePropertyImpl:
1 | public class InjectionServicePropertyImpl implements InjectionService { |
添加配置文件 classpath:spring-injection-property.xml:
1 | <?xml version="1.0" encoding="UTF-8"?> |
添加测试 TestInjectionProperty:
1 | @RunWith(BlockJUnit4ClassRunner.class) |
构造注入
添加 InjectionServiceConstructorImpl:
1 | public class InjectionServiceConstructorImpl implements InjectionService { |
添加配置文件 spring-injection-constructor.xml:
1 | <?xml version="1.0" encoding="UTF-8"?> |
添加测试 TestInjectionConstructor
1 | @RunWith(BlockJUnit4ClassRunner.class) |