-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown when trying out the provided example #10
Comments
I've just checked by re-running both Play 2.4 and 2.5 examples and they are running fine. Can you please share how are you running the examples? e.g. steps and commands in SBT. Regarding passing a message, can you be more specific which part of the code / examples you are referring to? The |
More or less as the example.
A view:
And a home controller:
As the example, which don't compile, since the @message is not used in the call. But even with the message, it complains of having no default constructor I would guess because the class is defined like this: |
I just realised The error makes sense now since it's trying to find a resolution for a Play 2.4package com.builtamont.modules
import com.google.inject.{AbstractModule, Provides}
import net.codingwell.scalaguice.ScalaModule
import com.builtamont.play.pdf.PdfGenerator
class ApplicationModule extends AbstractModule with ScalaModule {
/** Module configuration + binding */
def configure(): Unit = {}
/**
* Provides PDF generator implementation.
*
* @return PDF generator implementation.
*/
@Provides
def providePdfGenerator(): PdfGenerator = {
val pdfGen = new PdfGenerator()
pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf"))
pdfGen
}
} Play 2.5package com.builtamont.modules
import com.google.inject.{AbstractModule, Provides}
import net.codingwell.scalaguice.ScalaModule
import play.api.Environment
import com.builtamont.play.pdf.PdfGenerator
class ApplicationModule extends AbstractModule with ScalaModule {
/** Module configuration + binding */
def configure(): Unit = {}
/**
* Provides PDF generator implementation.
*
* @param env The current Play app Environment context.
* @return PDF generator implementation.
*/
@Provides
def providePdfGenerator(env: Environment): PdfGenerator = {
val pdfGen = new PdfGenerator(env)
pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf"))
pdfGen
}
} They are both referenced within
I'll update the repo later today. |
Ah. Thanks! |
Hi @pierce-build-user , I've pushed the repo update as a PR (refer to the above), please have a look. I have to run now but I'll merge the PR to NOTE: Since the package name is updated, you'll need to update your |
Merged in |
Hi @pierce-build-user , let me know if you still have any problem... Otherwise I'll automatically close this in 48 hours. |
Context
Running you example, I would expect it to work, instead I experience the following exception:
Could not find a suitable constructor in com.builtamont.play.pdf.PdfGenerator. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at com.builtamont.play.pdf.PdfGenerator.class(PdfGenerator.scala:53)
while locating com.builtamont.play.pdf.PdfGenerator
Also, this coed does not compile since your "example" template expect a message, and you call it without.
Definition of Done
Working code, or updated documentation that explain the use of inject into HomeController
The text was updated successfully, but these errors were encountered: