2016-03-20 19 views
1

Oyunun web sitesindeki documentation'u izleyerek Aktörüm şu şekilde yapılandırılmıştır;Bir Aktöre Yapılandırma ve Hizmeti Enjekte Etme

public class SuggestionActor extends UntypedActor { 


    public static Props props = Props.create(SuggestionActor.class); 

    private DAOService service; 
    private Configuration config; 

    @Inject 
    public SuggestionActor(DAOService service, Configuration config) { 
     this.service = service; 
     this.config = config; 
    } 


    @Override 
    public void onReceive(Object msg) throws Exception { 
     if(msg instanceof SayHello) { 
      // check if msg comes 
      Logger.info(((SayHello) msg).name + config.getString("dao.mode")); 
     } 
    } 
} 

- (dosyasına koyarak etkinleştirilmiş)

public class ActorProtocols { 

    public static class SayHello{ 
     public final String name; 


     public SayHello(String name) { 
      this.name = name; 
     } 
    } 
} 

MyModule

public class MyModule extends AbstractModule implements AkkaGuiceSupport { 

    @Override 
    protected void configure() { 
     bindActor(SuggestionActor.class, "suggestion-actor"); 
    } 
} 

Benim Kontrolör

@Singleton 
public class SuggestionController extends Controller { 

    private static Logger.ALogger LOGGER = Logger.of(SuggestionController.class); 

    @Inject @Named("suggestion-actor") 
    private ActorRef suggestionActor; 

    public Result suggest(String message) { 
     ask(suggestionActor, new SayHello(message), 10000); 
    } 
} 

Ben aracılığıyla benim DAO nesne ve Yapılandırma enjekte çalışırsanız SuggestionActor, Pl şirketinde constructor injection ay a Atılarak neden: java.lang.IllegalArgumentException: sınıf aktörleri üzerinde eşleşen bir kurucu bulunamadı.Örnekler için hata: []

Fikirler?

cevap

0

Aynı anda Props kullanırken (benim denetleyicimde) bileşenleri, SuggestionActor içine enjekte etmek için Guice kullanmaya çalışıyordum. Bir kez Sahneyi kaldırdığımda, her şey iyi çalışmaya başladı. Props kullanmak istiyorsanız, bu SO Post takip eder.

İlgili konular