I agree to use constructor by name approach. But what's wrong with classOf 
approach?
I have upgraded microservice from play 2.4 to play 2.5 and observed same 
issue. I fixed 1st error bu using constructor by name approach, but later 
another same issue observed. As this error pops runtime, there is no way to 
be sure if migration is successful. Only option I have is to replace all 
the classOf occurrences  with constructor by name.


On Tuesday, February 2, 2016 at 11:39:24 PM UTC+5:30, Heiko Seeberger wrote:
>
> Why do you think that the `Props` factory taking the actor constructor by 
> name is discouraged? It’s the opposite: You definitely SHOULD use it, the 
> other approach is using reflection at runtime and is not refactoring safe.
>
> Cheers
> Heiko
>
> --
>
> *Heiko Seeberger*
> Home: heikoseeberger.de
> Twitter: @hseeberger <https://twitter.com/hseeberger>
> Public key: keybase.io/hseeberger
>
> On 01 Feb 2016, at 20:46, steven richardson <stevenjohn...@gmail.com 
> <javascript:>> wrote:
>
> I am running into an issue using Props.create when providing a class and 
> its arguments. The example below is contrived but will hopefully serve its 
> purpose.
>
> trait Provider {}
>
>
> class DefaultProvider extends Provider {}
>
> class MyActor(provider: Provider) extends Actor {
>   def receive = ...
> }
>
>
> Then let's say I am injecting the provider using Guice or another 
> container:
>
> class ProviderPropsFactory @Inject()(protected val provider: Provider) {
>   def buildProps: Props = Props.create(classOf[MyActor], provider)
> }
>
>
> At runtime if I try to start an actor using these props as shown here, I 
> get an IllegalArgumentException when Akka attempts to find the matching 
> constructor for the actor since it is only seems to match on the concrete 
> type rather than allowing a compatible trait or an abstract type from the 
> instance's hierarchy. 
>
> system.actorOf(factory.buildProps)
> java.lang.IllegalArgumentException: no matching constructor found on class 
> com.sample.MyActor for arguments [class com.sample.DefaultProvider]
>  at akka.util.Reflect$.error$1(Reflect.scala:82) ~[akka-actor_2.11-2.3-bin
> -rp-15v01p06.jar:na]
>  at akka.util.Reflect$.findConstructor(Reflect.scala:106) ~[akka-actor_2.
> 11-2.3-bin-rp-15v01p06.jar:na]
>  at akka.actor.ArgsReflectConstructor.<init>(Props.scala:353) ~[akka-
> actor_2.11-2.3-bin-rp-15v01p06.jar:na]
>  at akka.actor.IndirectActorProducer$.apply(Props.scala:312) ~[akka-
> actor_2.11-2.3-bin-rp-15v01p06.jar:na]
>  at akka.actor.Props.producer(Props.scala:179) ~[akka-actor_2.11-2.3-bin-
> rp-15v01p06.jar:na]
>  at akka.actor.Props.<init>(Props.scala:192) ~[akka-actor_2.11-2.3-bin-rp-
> 15v01p06.jar:na]
>  at akka.actor.Props$.create(Props.scala:99) ~[akka-actor_2.11-2.3-bin-rp-
> 15v01p06.jar:na]
>
> I could use this snippet  below instead which I know would work, but this 
> type of approach is discouraged/deprecated and I would like to be doing 
> things the recommended way. Do you have any suggestions?
>
> class ProviderPropsFactory @Inject()(protected val provider: Provider) {
>   def buildProps: Props = Props(new MyActor(provider))
> }
>
>
> Any and all help is appreciated.
>
> Thanks,
> Steve
>
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: 
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+...@googlegroups.com <javascript:>.
> To post to this group, send email to akka...@googlegroups.com 
> <javascript:>.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to