现场注入
导入org.apache.tapestry5.ioc.annotations。 注入; 导入org.apache.tapestry5.ioc.annotations。 注入服务; ... 公共类AuthenticationFilter实现ComponentRequestFilter{ @注入服务(“HttpBasic”) 私有身份验证服务basicAuthService; @注入服务(“HttpDigest”) private AuthenticationService digestAuthService; @注入 私人响应; ... }
导入javax.inject。 注入; 导入javax.inject。 命名; ... 公共类AuthenticationFilter实现ComponentRequestFilter{ @注入@Named(“HttpBasic”) 私有身份验证服务basicAuthService; @注入@Named(“HttpDigest”) private AuthenticationService digestAuthService; @注入 私人响应; ... }
构造器注入
公共级轿车{ 公共Car(){…} @注入 公共汽车(发动机){…} }
公共级轿车{ 公共Car(){…} 公共汽车(发动机){…} }
公共级轿车{ 公共Car(){…} @注入 公共汽车(发动机){…} 公共汽车(发动机、记录器记录器){…} }
注入页面和组件
公共类索引{ @注入 私人请求请求; @javax.注入。 注入 私有组件资源; @javax.注入。 注入 @命名(“法语问候语”) 私人迎宾员; @javax.注入。 注入 @符号(SymbolConstants.PRODUCTION_MODE) 私有布尔productionMode; 无效onActivate(){…} }
标记/限定符注释
公共类索引{ @注入 @法语 私人迎宾员; }
@已记录 @保留(RetentionPolicy.RUNTIME) @目标(ElementType.FIELD) @javax.注入。 限定符 public@interface法语{ }
方法注入
公共级轿车{ 专用引擎; public void setEngine(引擎引擎){ this.engine=发动机; } }
公共类TapestryModule{ @贡献(BindingSource.class) 公共静态无效提供绑定( MappedConfiguration<String,BindingFactory>cfg, @命名(“PropBindingFactory”) 绑定工厂propBindingFactory, @命名(“MessageBindingFactory”) 绑定工厂消息绑定因子){ cfg.add(绑定常量.PROP, propBindingFactory); cfg.add(BindingConstants.MESSAGE, 消息绑定工厂); } ... }