泛型依赖注入
来源:互联网 发布:ubuntu 添加路由 编辑:程序博客网 时间:2024/06/07 21:19
以下类都在包com.po中
实体类:
User
第一层:
BaseRepository<T> BaseService<T>
BaseService<T>里的成员变量指向了BaseRepository<T>,要为其添加@Autowired注解
第二层:
UserRepository UserService
他们两个继承对应的父类,要分别为各自添加@Repository注解和@Service注解
public class User {}
public class BaseRepository<T> {}
public class BaseService<T> {@Autowiredprotected BaseRepository<T> repository;public void out(){System.out.println(repository);}}
@Repositorypublic class UserRepository extends BaseRepository<User>{}
@Servicepublic class UserService extends BaseService<User>{}
主方法中调用:
public class Main {public static void main(String[] args) {ApplicationContext ctx=new ClassPathXmlApplicationContext("test.xml");UserService us=(UserService) ctx.getBean("userService");us.out();}}配置文件test.xml主要内容
<context:component-scan base-package="com.po"></context:component-scan>①在类上有了注解;②在xml文件中扫描了该类;就可以通过类名首字母小写来getBean
阅读全文
0 0
- 泛型依赖注入
- 泛型依赖注入
- 泛型依赖注入
- 泛型依赖注入
- 泛型依赖注入
- 泛型依赖注入
- 泛型依赖注入
- spring 泛型依赖注入
- spring泛型依赖注入
- Spring 泛型依赖注入
- Spring 泛型依赖注入
- Spring 泛型依赖注入
- 十二泛型依赖注入
- Spring_泛型依赖注入
- Spring4学习笔记-泛型依赖注入
- 浅谈spring4泛型依赖注入
- Spring笔记3-泛型依赖注入
- spring4.0之泛型依赖注入
- 8月22号 JDBC,线程,网络编程补充
- 数据结构之贪心算法(背包问题的思考)
- STL 中的Map用法
- eclipse 中的注释 快捷键 多行注释快捷键 单行注释快捷键
- 基于Dragonboard 410c的智能遥控器(一)
- 泛型依赖注入
- 1053. Path of Equal Weight (30)
- 关于使用hibernate中遇到的问题
- Spyder Ipython Console卡在Connecting to kernel的解决方案
- postgresql----Btree索引
- 数据库利器Navicat最全快捷键整理
- 安卓一键清理工具
- MIR7/MIRO 贷项凭证/事后借记/后续贷记
- Android AMS 浅析