Spring4学习笔记-泛型依赖注入
来源:互联网 发布:sql查询分析器下载 编辑:程序博客网 时间:2024/05/22 06:47
泛型依赖注入
BaseRepository.java
package com.spring.beans.generic.di;public class BaseRepository <T>{}
BaseService.java
package com.spring.beans.generic.di;import org.springframework.beans.factory.annotation.Autowired;public class BaseService <T>{@Autowiredprotected BaseRepository<T>baseRepository;public void add() {System.out.println("add...");System.out.println(baseRepository);}}
UserRepository.java
package com.spring.beans.generic.di;import org.springframework.stereotype.Repository;@Repositorypublic class UserRepository extends BaseRepository<User>{}
UserService.java
package com.spring.beans.generic.di;import org.springframework.stereotype.Service;@Servicepublic class UserService extends BaseService<User>{}
beans-generic-di.xml
<?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:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><context:component-scan base-package="com.spring.beans.generic.di" ></context:component-scan></beans>
Main.java
public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans-generic-di.xml");UserService userService = (UserService) applicationContext.getBean("userService");userService.add();}
输出
2014-9-22 20:20:17 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@8b819f: startup date [Mon Sep 22 20:20:17 CST 2014]; root of context hierarchy
2014-9-22 20:20:17 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans-generic-di.xml]
add...
com.spring.beans.generic.di.UserRepository@c01e99
本文出自 “优赛工作室” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1557073
0 0
- Spring4学习笔记-泛型依赖注入
- 浅谈spring4泛型依赖注入
- spring4.0之泛型依赖注入
- Spring4学习笔记----Spring的依赖注入详解
- Spring4第三讲学习笔记,依赖注入dependency injection
- 四.Spring4学习-----依赖注入DI
- Spring4新特性:泛型限定式依赖注入
- Spring4新特性:泛型限定式依赖注入
- Spring4.0新特性--泛型依赖注入
- Spring4新特性:泛型限定式依赖注入
- Spring4新特性:泛型限定式依赖注入
- Spring4.0之后的新特性--泛型依赖注入
- J2EE系列之Spring4学习笔记(三)--IOC详解(依赖注入)
- Spring4学习笔记(三):依赖注入的方式与细节
- spring4泛型注入
- Spring学习笔记之泛型依赖注入
- Spring学习笔记之泛型依赖注入
- 1. Spring4.1-依赖注入
- Java对象与xml文件互转
- javascript使用正则表达式
- 重金属项目笔记
- servlet复习(五)cookie管理
- Spring4学习笔记
- Spring4学习笔记-泛型依赖注入
- Spring4学习笔记-AOP前传之动态代理
- 【Leetcode】之Permutations II
- 招聘相关笔记
- Spring4学习笔记-AOP(基于注解的方式)
- Spring4学习笔记-AOP(基于配置文件的方式)
- Spring4学习笔记-JDBC
- Spring4学习笔记-声明式事务(基于注解的方式)
- Spring4学习笔记-声明式事务(基于配置文件的方式)