Spring入门第十五课
泛型依赖注入

看代码:
package logan.spring.study.generic.di;
public class BaseRepository<T> {
}
package logan.spring.study.generic.di;
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 logan.spring.study.generic.di; import org.springframework.stereotype.Service; @Service
public class UserService extends BaseService<User>{ }
package logan.spring.study.generic.di;
public class User{
}
package logan.spring.study.generic.di; import org.springframework.stereotype.Repository; @Repository
public class UserRepository extends BaseRepository<User>{ }
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="logan.spring.study.generic.di"></context:component-scan> </beans>
package logan.spring.study.generic.di; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-generic.xml");
UserService userService = (UserService) ctx.getBean("userService");
userService.add(); } }
输出结果:
五月 27, 2017 2:04:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@42110406: startup date [Sat May 27 14:04:02 CST 2017]; root of context hierarchy
五月 27, 2017 2:04:02 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans-generic.xml]
add...
logan.spring.study.generic.di.UserRepository@43a0cee9
Spring入门第十五课的更多相关文章
- Spring入门第十九课
后置通知 看代码: package logan.study.aop.impl; public interface ArithmeticCalculator { int add(int i, int j ...
- Spring入门第十八课
Spring AOP AspectJ:Java社区里最完整最流行的AOP框架 在Spring2.0以上的版本中,可以使用基于AspectJ注解或者基于XML配置的AOP 看代码: package lo ...
- Spring入门第十六课
接上一次讲课 先看代码: package logan.spring.study.annotation.repository; public interface UserRepository { voi ...
- Spring入门第十四课
基于注解的方式配置bean(基于注解配置Bean,基于注解来装配Bean的属性) 在classpath中扫描组件 组件扫描(component scanning):Spring能够从classpath ...
- Spring入门第十二课
Bean的配置方法 通过工厂方法(静态工厂方法&实例工厂方法),FactoryBean 通过调用静态工厂方法创建Bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中,当客户 ...
- Spring入门第十课
Spring表达式语言:SpEL Spring表达式语言(简称SpEL)是一个支持运行时查询和操作对象图的强大的表达式语言. 语法类似于EL:SpEL使用#{...}作为定界符,所有在大括号中的字符都 ...
- 大数据入门第十五天——HBase整合:云笔记项目
一.功能简述 1.笔记本管理(增删改) 2.笔记管理 3.共享笔记查询功能 4.回收站 效果预览: 二.库表设计 1.设计理念 将云笔记信息分别存储在redis和hbase中. redis(缓存):存 ...
- Spring入门第二十五课
使用具名参数 直接看代码: db.properties jdbc.user=root jdbc.password=logan123 jdbc.driverClass=com.mysql.jdbc.Dr ...
- NeHe OpenGL教程 第四十五课:顶点缓存
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
随机推荐
- EasyNVR+EasyDSS实现简单套路的RTMP、微信直播、录像、回放方案
安防领域HLS直播问题探讨 近期外出交流比较多,在之前的一篇博客<一种流量成本节省60%以上的手机直播微信直播H5直播幼儿园直播方案>我们说到了一种模式,就是当我们在做最近火热的幼儿园直播 ...
- 时间写入文件名 nohup 原理 Command In Background your shell may have its own version of nohup
echo 123 > `date +%Y-%m-%d-%H.tmp` echo 123 > /home/`date +%Y-%m-%d-%H.tmp` nohup --help [root ...
- ridge regression 无惩罚,导致预测结果空间过大而无实用价值
[ biased regression methods to reduce variance---通过偏回归来减小方差] https://onlinecourses.science.psu.edu/s ...
- bmdiff snappy lzw gzip
https://github.com/google/snappy Introduction [速度第一,压缩比适宜] [favors speed over compression ratio] Sna ...
- property 中的strong 与weak
strong关键字与retain关似,用了它,引用计数自动+1,用实例更能说明一切 @property (nonatomic, strong) NSString *string1; @property ...
- spring-boot5
Spring Boot集成MyBatis: (1)新建maven project;取名为:spring-boot-mybatis (2)在pom.xml文件中引入相关依赖: (3)创建启动类App.j ...
- linux中fflush函数和printf函数 【转】
本文转载自:http://blog.chinaunix.net/uid-30058258-id-5029847.html printf是一个行缓冲函数printf函数是标准函数,最终会调用到系统调用函 ...
- Contiki学习资料
一.官方网站 官网主页:http://contiki-os.org/ 资源和支持:http://contiki-os.org/support.html The Contiki Community: h ...
- PYTHON 爬虫笔记十一:Scrapy框架的基本使用
Scrapy框架详解及其基本使用 scrapy框架原理 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了 ...
- apace搭建站点
Listen 127.0.0.1:3310<VirtualHost *:3306> ServerName 127.0.0.1:3306 DocumentRoot "F:/Baid ...