Tapestry @Inject无法在POJO中注入服务。这个服务被绑定在我的Module中…
public static void bind( ServiceBinder binder ) {
...
binder.bind( DeviceProfileHelperService.class, DeviceProfileHelperServiceImpl.class );
...
}
…我希望@Inject能够在我的POJO中找到它。
@Inject
private DeviceProfileHelperService deviceProfileHelperSvc;
...
@Override
public BasicDBObject makeEntity( String platform, String serialNumber, List<DBObject> configs ) {
final BasicDBObject response = new BasicDBObject( "resp", configs );
// FIXME: deviceProfileHeplperSvc is null here, why?
final String bindingUri = deviceProfileHelperSvc.makeBindURI( platform, serialNumber );
response.append( "bindingUri", bindingUri );
return response;
}
…但实际发生的是,deviceProfileHelperSvc是空的,当我试图调用它。我哪里做错了?@Inject不应该根据活页夹的类型来解决这个问题吗?绑定(DeviceProfileHelperService.class, DeviceProfileHelperServiceImpl.class)绑定设置在我的模块?
我怀疑这很重要,但我们是Tapestry 5.3.6。
Tapestry只能@Inject到它管理的服务中。我只能假设您已经使用"new"
如果您只有一个DeviceProfileHelperService
的实现,请尝试在DeviceProfileHelperService
的实现上使用@Named
属性来识别它。
。
@Named
public class DeviceProfileHelperServiceImpl implements DeviceProfileHelperService {
...
}