java - Google Guice Assisted Inject object is null -




i need create objects user defined data @ runtime.to have used google guice assisted inject.but when run test throws null pointer exception.please let me know made mistake.

iartifacts interface

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 interface

public interface artifactsfactory {      iartifacts create(productprofile productprofile); } 

module class

@override     protected void configure() {     install(new factorymodulebuilder().implement(iartifacts.class,artifactsservice.class).build(artifactsfactory.class)); } 

testartifacts.java

public class testartifacts {      @inject // obj null     private artifactsfactory artifactsfactory;      private  iartifacts s;      public testartifacts(){      }      public void getdata(){         //pass custom data factory         this.s=artifactsfactory.create(products.gtnexus_qa.get());         system.out.println(s.getartifactsversions());     }   }   

rest endpoint

    @get     @path("/test")     @produces(mediatype.application_json)     public string getartifacts(){       new testartifacts().getdata();     } 

you created instance of class testartifacts on own in rest endpoint class of classes need created guice framework , not you.

so how should guice framework inject class when create them new? need inject class testartifacts rest endpoint , rest endpoint has created guice too.

update:

maybe link you

https://sites.google.com/a/athaydes.com/renato-athaydes/posts/jersey_guice_rest_api





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -