Closed skress closed 5 years ago
This is almost certainly https://github.com/playframework/playframework/issues/6207
Which leads us to TypeConversions.scala#L66 which uses mirror which is indeed bound to the classloader of this library and not the classloader of the type in question.
I wonder though if it could simply be swapped for scalaType.dealias.getClass, or if there is some reason @Vrolijkx didn't do that in the first place.
If you meant getting the mirror like runtimeMirror(scalaType.dealias.getClass.getClassLoader)
, then this did not work.
What helped is adding the mirror as parameter to TypeConversions.scala#L60 and getting the mirror from the TypeTag.
I have implemented it in a fork and it seems to work (i.e. my play project works now): https://github.com/skress/scala-guice/commit/913264e67ee91340eca9af4e1e55a67a19970074
I can create a PR - but I am not sure if there are any other (unwanted) side effects of that change.
Assuming you ran the tests and they passed, that should be fine. Make a PR and I'll test locally too.
First of all: thanks a lot for maintaining this library, it is really helpful.
I've run into problems with scala-guice after upgrading to 4.2.2 in combination with Play framework's dev mode. There is a minimal Play project which you could use to reproduce the error: https://github.com/skress/issue-play-scala-guice
If I am not doing anything terribly wrong then even this simple configuration does not work:
The exception looks like this:
Reverting the two changes from
Manifest
toTypeTag
inScalaModule.scala
(https://github.com/codingwell/scala-guice/commit/8ebf64e57d08e08c9472210a5bac694d5a99e2ba#diff-3f5a5d294b9751c91b703f2e10f25a04) seems to fix the issue.The reason for the problem seems to be that the classloader that scala-guice sees is not the classloader that Play uses to load the project's classes in dev mode (running the app in production mode does not exhibit the error.) In Play's dev mode the project's dependencies are loaded, the framework is started and Play then creates a new classloader that loads the project's classes. When you change anything in your project the changes are compiled, the classloader is abandoned and a new one is created that loads the just compiled classes.
From my limited understanding this should explain why scala-guice does not work. But it should have never worked. What's the difference between
Manifest
andTypeTag
that one is working and the other is not, even if in both cases the same (wrong) classloader is used?