No implementation Slick DatabaseConfigProvider was bound - scala

I have just created a dummy project and try to integrate Play with Slick. I followed the official tutorial but unfortunatelly did not manage do run it properly.
Everytime I try to run the app I get following error:
play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:
1) No implementation for play.api.db.slick.DatabaseConfigProvider was bound.
while locating play.api.db.slick.DatabaseConfigProvider
for the 1st parameter of com.reciper.repository.UserRepository.<init>(UserRepository.scala:13)
Here are my configs:
build.sbt
scalaVersion := "2.12.2"
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test
libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.3"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "3.0.3"
libraryDependencies += "org.postgresql" % "postgresql" % "42.2.4"
application.conf
play.evolutions {
autoApply = true
}
#Slick for Play
slick.profile = "slick.jdbc.PostgresProfile$"
slick.db.driver = "org.postgresql.Driver"
slick.db.url = "jdbc:postgresql://localhost:5432/reciper"
slick.db.user = "postgres"
slick.db.password = "postgres"
UserRepository.scala
#Singleton
class UserRepository #Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
(implicit executionContext: ExecutionContext) extends HasDatabaseConfigProvider[PostgresProfile] { ..codehere.. }
HomeController.scala
#Singleton
class HomeController #Inject()(repo: UserRepository) {...}
plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.13")
I have been struggling with it for more than 3 days now and lost my hope that it will actually work.. tried many options, none worked
Do you know what is missing or wrong? Let me know if you need any other file
Thanks!

Following configuration in application.conf works
build.sbt
"com.typesafe.play" %% "play-slick" % "3.0.3"
application.conf
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://ec2-54-217-243-228.eu-west-1.compute.amazonaws.com:5432/d344onl0761ji5"
slick.dbs.default.db.user=user
slick.dbs.default.db.password="pass"

Related

How to fix the No implementation for play.api.db.DBApi was bound. with play 2.8.13

we are upgrading the tech stack versions of my project due to log4j vulnerability.
SBT 1.6.2,
Scala 2.13.6,
play_scala 2.8.13
I used below dependencies to connect database and I mentioned db configurations in application.conf file.Also using customApplicationLoader.scala file
"com.typesafe.play" %% "play-slick" % "5.0.0",
"org.postgresql" % "postgresql" % "9.4-1206-jdbc42",
"com.typesafe.play" %% "play-slick-evolutions" % "5.0.0" % Test
import play.api.ApplicationLoader
import play.api.inject.guice.{GuiceApplicationLoader, GuiceApplicationBuilder}
class CustomApplicationLoader extends GuiceApplicationLoader {
override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = {
super.builder(context).disableCircularProxies(true)
}
}
but I'm facing the below issue
How can I resolve this please suggest here. Thank you
Thank you all, After adding libraryDependencies += "com.typesafe.play" %% "play-guice" % "2.8.15" dependency and adding below configurations in application.conf my issue resolved.
play.evolutions.enabled = false
play.evolutions.db.default.autoApply = true
play.modules.disabled += "play.api.db.evolutions.EvolutionsModule"

Need help in setup of Redshift and Scala using Play

I am new to Scala and Redshift, I am trying to connect redshift with play framework. I have tried a couple of things but still not able to connect. i am using these configurations
db.default.driver=org.redshift.Driver
db.default.url="jdbc:redshift://url:5439/myDb?"
db.default.username="name"
db.default.password="password"
play.modules.enabled += "scalikejdbc.PlayModule"
# scalikejdbc.PlayModule doesn't depend on Play's DBModule
play.modules.disabled += "play.api.db.DBModule"
My SBT file looks like this
scalaVersion := "2.12.4"
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test
// https://mvnrepository.com/artifact/com.typesafe.play/anorm
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "3.2.1",
"com.h2database" % "h2" % "1.4.196",
"ch.qos.logback" % "logback-classic" % "1.2.3"
)
// https://mvnrepository.com/artifact/com.amazon/redshift-jdbc41
resolvers += "redshift" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
libraryDependencies += "com.amazon.redshift" % "redshift-jdbc4" % "1.2.10.1009
"
I am getting this error connecting DB
Setup Redshift with Play Scala
Application.conf
db.default.driver=com.amazon.redshift.jdbc4.Driver
db.default.url="jdbc:redshift://url:5439/db"
db.default.username="name"
db.default.password="password"
SBT file
libraryDependencies += jdbc
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "3.2.0",
"org.scalikejdbc" %% "scalikejdbc-config" % "3.2.0",
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.6.0-scalikejdbc-3.2"
)
// https://mvnrepository.com/artifact/com.amazon/redshift-jdbc41
resolvers += "redshift" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
libraryDependencies += "com.amazon.redshift" % "redshift-jdbc4" % "1.2.10.1009"
Controller
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
import play.api.db._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
#Singleton
class HomeController #Inject()(db: Database, cc: ControllerComponents) extends AbstractController(cc) {
/**
* Create an Action to render an HTML page.
*
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
def index() = Action {
var outString = "Number is "
val conn = db.getConnection()
try {
val stmt = conn.createStatement
val rs = stmt.executeQuery("SELECT 9 as testkey ")
while (rs.next()) {
outString += rs.getString("testkey")
}
} finally {
conn.close()
}
Ok(outString)
// implicit request: Request[AnyContent] =>
//
// Ok(views.html.index())
}
}

Scala Akka Streams project fails to compile, "value ~> is not a member of akka.streams.Outlet[In]"

I am using the Akka Streams API in a Scala project, working in Intellij IDEA with the SBT plugin. I have a worker pool Flow as described here: https://doc.akka.io/docs/akka/current/scala/stream/stream-cookbook.html. Here is my code:
package streams
import akka.NotUsed
import akka.stream.scaladsl.{Balance, Flow, GraphDSL, Merge}
import akka.stream.{FlowShape, Graph}
object WorkerPoolFlow {
def apply[In, Out](
worker: Flow[In, Out, Any],
workerCount: Int):
Graph[FlowShape[In, Out], NotUsed] = {
GraphDSL.create() { implicit b =>
val balance = b.add(Balance[In](workerCount, waitForAllDownstreams = true))
val merge = b.add(Merge[Out](workerCount))
for (i <- 0 until workerCount)
balance.out(i) ~> worker.async ~> merge.in(i)
FlowShape(
balance.in,
merge.out)
}
}
}
For some reason the project is now failing to compile, giving this error: value ~> is not a member of akka.stream.Outlet[In].
It compiled fine until today. The only change I am aware of making is installing a Scala linter plugin scalafmt, and importing a few new libraries in build.sbt. Here is my build.sbt:
name := "myProject"
version := "0.1"
scalaVersion := "2.11.11"
unmanagedJars in Compile += file("localDep1.jar")
unmanagedJars in Compile += file("localDep2.jar")
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.6"
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.6"
libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.5.6" % Test
libraryDependencies += "com.typesafe.akka" %% "akka-stream-testkit" % "2.5.6" % Test
libraryDependencies += "com.47deg" %% "fetch" % "0.6.0"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
I have tried reloading SBT, building from SBT outside of IDEA, removing and re-adding dependencies, and cleaning the project, with no luck.
Import GraphDSL.Implicits._:
object WorkerPoolFlow {
def apply[In, Out](
worker: Flow[In, Out, Any],
workerCount: Int):
Graph[FlowShape[In, Out], NotUsed] = {
import GraphDSL.Implicits._
GraphDSL.create() { implicit b =>
...
}
}
}

Symbol 'type <none>.scalacheck.Shrink' is missing from the classpath

I have the following ScalaCheck unit test using Mockito:
import org.scalatest.mockito.MockitoSugar
import org.mockito.Mockito.when
import org.scalatest.prop.PropertyChecks
import org.mockito.Mockito.verify
class PlayerTest extends org.scalatest.FunSuite with MockitoSugar with PropertyChecks {
test("doesn't accept anything but M") {
val mockIOHandler = mock[IOHandler]
val name = "me"
val player = new Player(name)
when(mockIOHandler.nextLine).thenReturn("m")
val apiUser = new Player("player1")
apiUser.chooseHand(mockIOHandler)
verify(mockIOHandler).write("some value")
}
}
In my build.sbt I have the following dependencies:
scalaVersion := "2.12.2"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"
// https://mvnrepository.com/artifact/org.mockito/mockito-core
libraryDependencies += "org.mockito" % "mockito-core" % "1.8.5"
For it, I am getting this error:
Error:(12, 41) Symbol 'type <none>.scalacheck.Shrink' is missing from the classpath.
This symbol is required by 'value org.scalatest.prop.GeneratorDrivenPropertyChecks.shrA'.
Make sure that type Shrink is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'GeneratorDrivenPropertyChecks.class' was compiled against an incompatible version of <none>.scalacheck.
test("doesn't accept anything but M") {
Any idea what could be wrong?
Adding scalacheck did the trick for me
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.+"
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.13.+"

java.lang.NoSuchMethodError with Scala actors

I have a simple Scala application (taken from here) which I want to test. The whole project is compiled successfully with SBT. However, when I launch the tests with sbt test I get the following error message:
Could not run test ConnectionTest:java.lang.NoSuchMethodError: akka.actor.Props$.apply(Lscala/Function0;)Lakka/actor/Props;
From the internet search, I get the impression that some of my versioning is not compatible but that is merely a guess. What may be wrong?
[Test Case]
import akka.actor.{Props, Actor, ActorSystem, ActorRef}
import akka.testkit.{TestKit, TestActorRef, ImplicitSender}
import org.scalatest.{WordSpecLike, BeforeAndAfterAll}
import org.scalatest.matchers.MustMatchers
class ConnectionTest extends TestKit(ActorSystem("ConnectionSpec"))
with WordSpecLike
with MustMatchers
with BeforeAndAfterAll {
override def afterAll() { system.shutdown() }
"Server" must {
"bind to port " in {
// create server
val server = system.actorOf(Props[Server], name = "server")
expectMsg("Bound to /127.0.0.1:8888")
}
}
}
[build.sbt]
name := "MyApp"
version := "0.2"
scalaVersion := "2.10.4"
mainClass := Some("akka.Main")
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies +=
"com.typesafe.akka" %% "akka-actor" % "2.3.2"
libraryDependencies +=
"com.typesafe.akka" %% "akka-testkit" % "2.1.4" % "test"
libraryDependencies +=
"org.scalatest" % "scalatest_2.10" % "2.0" % "test"
You need to use the same version of Akka for testkit.
libraryDependencies +=
"com.typesafe.akka" %% "akka-testkit" % "2.1.4" % "test"
should be
libraryDependencies +=
"com.typesafe.akka" %% "akka-testkit" % "2.3.2" % "test"