Spring笔记3-泛型依赖注入
2017-08-27 00:28
323 查看
springContext.xml
<beans> <context:componemt-scan base-package="com.test"></context:componemt-scan> </beans>
package com.test; public class BaseRepository<T> { }
package com.test; import org.springframework.beans.factory.annotation.Autowired; public class BaseService<T> { @Autowired protected BaseRepository<T> repository; public void add() { System.out.println("add..."); System.out.println(repository); } }
package com.test; public class User { }
package com.test; import org.springframework.stereotype.Repository; @Repository public class UserRepository extends BaseRepository<User> { }
package com.test; import org.springframework.stereotype.Service; @Service public class UserService extends BaseService<User> { }
public class Test { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("springContext.xml"); UserService userService = (UserService) ctx.getBean("userService"); userService.add(); } }
相关文章推荐
- Spring学习笔记之泛型依赖注入
- Spring学习笔记之泛型依赖注入
- Spring4学习笔记-泛型依赖注入
- Spring 4.xx新特性:泛型依赖注入
- Spring4第三讲学习笔记,依赖注入dependency injection
- Spring4新特性:泛型限定式依赖注入
- Spring实战(第4版) Spring Inaction 笔记(第一章)依赖注入和AOP
- Spring的泛型依赖注入
- spring注解基于Annotation的依赖注入配置笔记
- Spring-13:泛型依赖注入(Spring4.X新特性)
- spring学习笔记-依赖注入
- Spring学习笔记--依赖注入
- Spring学习笔记(5)----依赖注入的简单实现
- Spring学习笔记(5)----依赖注入的简单实现
- Spring4 实战笔记(1):装配bean—依赖注入的本质
- spring学习笔记3——注入依赖对象
- Spring学习--泛型依赖注入
- spring笔记--依赖注入之针对不同类型变量的几种注入方式
- Spring2.5学习笔记1-控制反转-依赖注入类型
- (学习笔记)spring入门之Bean的依赖注入