當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring学习笔记十二---泛型依赖注入
生活随笔
收集整理的這篇文章主要介紹了
Spring学习笔记十二---泛型依赖注入
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
package?generic_di;import?org.springframework.stereotype.Repository;@Repository public?class?BaseRepository<T>?{public?void?save()?{System.out.println("Repository?save?...");} }package?generic_di;import?org.springframework.stereotype.Repository;@Repository public?class?UserRepository?extends?BaseRepository<User>?{ } package?generic_di;import?org.springframework.beans.factory.annotation.Autowired; import?org.springframework.stereotype.Repository; import?org.springframework.stereotype.Service;@Service public?class?BaseService<T>?{@Autowiredprotected?BaseRepository<T>?baseRepository;public?void?add()?{System.out.println("Service?add?...");System.out.println(baseRepository);} } package?generic_di;import?org.springframework.stereotype.Service;@Service public?class?UserService?extends?BaseService<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.xsd"><context:component-scan?base-package="generic_di"></context:component-scan> </beans> package?generic_di;import?org.springframework.context.ApplicationContext; import?org.springframework.context.support.ClassPathXmlApplicationContext;public?class?Main?{public?static?void?main(String[]?args)?{ApplicationContext?ctx?=?new?ClassPathXmlApplicationContext("generic_di//application.xml");UserService?userService?=?(UserService)?ctx.getBean("userService");userService.add();} }轉(zhuǎn)載于:https://my.oschina.net/jimyao/blog/633157
總結(jié)
以上是生活随笔為你收集整理的Spring学习笔记十二---泛型依赖注入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP截取IE浏览器并缩小原图的方法
- 下一篇: jquery mobile页面切换效果(