我需要runtime.TO來創建用戶定義的數據對象一樣,我是用輔助inject.But當我運行我的測試 谷歌吉斯它拋出null
指針exception.Please讓我知道我犯了錯誤。谷歌吉斯輔助進樣對象爲空
IArtifacts接口
public interface IArtifacts {
MavenMetaDataXMLDTO getArtifactsVersions();
}
ArtifactsService.java
public class ArtifactsService implements IArtifacts {
private ProductProfile productProfile;
@Inject
public ArtifactsService(@Assisted ProductProfile productProfile){
System.out.println(productProfile.getArtifactManagementURL());
this.productProfile=productProfile;
}
@Override
public MavenMetaDataXMLDTO getArtifactsVersions() {
System.out.println(productProfile.getArtifactManagementURL());
return null;
}
}
ArtifactsFactory接口
public interface ArtifactsFactory {
IArtifacts create(ProductProfile productProfile);
}
模塊類
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(IArtifacts.class,ArtifactsService.class).build(ArtifactsFactory.class));
}
TestArtifacts.java
public class TestArtifacts {
@Inject // this obj is null
private ArtifactsFactory artifactsFactory;
private IArtifacts s;
public TestArtifacts(){
}
public void getdata(){
//Pass custom data to factory
this.s=artifactsFactory.create(Products.QA.get());
System.out.println(s.getArtifactsVersions());
}
}
REST端點
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public String getartifacts(){
new TestArtifacts().getdata();
}
感謝您的快速回復。你有任何樣品可供參考。 – gihan
看到我的更新。我添加了一個鏈接 –