做nGOM练习时,
Spring version:
通过web发送过来的get和post请求,通过注入的AdvertisementRepository serve.
这个ads是一个interface,在我们的project里只需定义一个空的interface:
我之前做的时候就很好奇,runtime时候,Spring总得帮我注入一个具体的实现class嘛,这个class类型到底是什么?
类型是这个JdkDynamicAopProxy:
练习里使用的bean container是AnnotationConfigWebApplicationContext,这种容器支持在Java code里手动注册bean:
在这里,AdvertisementResource bean被register:
这个Resource class里通过@Inject注入了AdvertisementRepository:
这个@Inject在call stack InjectionMetadata.inject里被解析并执行注入:
在这里生成interface的实现class - 创建proxy