I'm working on a Kafka streams application written in scala 2.13 project with the following Kamon packages:
libraryDependencies += "io.kamon" %% "kamon-datadog" % "2.5.4"
libraryDependencies += "io.kamon" %% "kamon-bundle" % "2.5.4"
libraryDependencies += "io.kamon" %% "kamon-kafka" % "2.5.4"
And the following Kamon configurations:
kanela {
show-banner = true
log-level = "DEBUG"
modules {
kafka-client-module {
name = "Kafka Clients(Producers|Consumers) Instrumentation Module"
stoppable = true
instrumentations = [
"kamon.kafka.instrumentation.ProducerInstrumentation",
"kamon.kafka.instrumentation.ConsumerInstrumentation"
]
within = [
"org.apache.kafka.clients.*",
]
}
}
}
But when I'm running the application, Kamon fails to find the instrumentation classes:
[Attach Listener] INFO 2022-08-07 19:01:30 Logger : Loading Kafka Clients(Producers|Consumers) Instrumentation Module
[Attach Listener] INFO 2022-08-07 19:01:30 Logger : ==> Loading kamon.kafka.instrumentation.ProducerInstrumentation
[Attach Listener] WARNING 2022-08-07 19:01:30 Logger : Error trying to load Instrumentation: kamon.kafka.instrumentation.ProducerInstrumentation with error: java.lang.ClassNotFoundException: kamon.kafka.instrumentation.ProducerInstrumentation
[Attach Listener] INFO 2022-08-07 19:01:30 Logger : ==> Loading kamon.kafka.instrumentation.ConsumerInstrumentation
[Attach Listener] WARNING 2022-08-07 19:01:30 Logger : Error trying to load Instrumentation: kamon.kafka.instrumentation.ConsumerInstrumentation with error: java.lang.ClassNotFoundException: kamon.kafka.instrumentation.ConsumerInstrumentation
[Attach Listener] INFO 2022-08-07 19:01:30 Logger : Retransformation Strategy activated for: Kafka Clients(Producers|Consumers) Instrumentation Module
I reloaded sbt.build, and can see kamon-kafka" % "2.5.4 in the dependencies list (in IntelliJ).
What could it be?
Related
I have a Gradle based Spring Boot app that I'm trying to deploy to the App Engine via the App Engine gradle plugin. The SQL instance (PostgreSQL) is up and running fine, I can connect to it locally through DataGrip and it works fine. Here's my application.properties file:
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
#################### GOOGLE CLOUD SETTINGS
spring.cloud.gcp.sql.enabled=true
spring.cloud.gcp.sql.database-name=db-name
spring.cloud.gcp.sql.instance-connection-name=app-name:europe-west2:db-name
When I try to deploy the app, I'm getting the following error (seems that it can't connect to the SQL instance):
A 2020-05-27T16:12:26.340839Z 2020-05-27 16:12:26.340 INFO 10 --- [ main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/db-name?socketFactory=com.google.cloud.sql.postgres.SocketFactory&cloudSqlInstance=instance-name:europe-west2:db-name with driver org.postgresql.Driver
A 2020-05-27T16:12:26.773138Z 2020-05-27 16:12:26.772 INFO 10 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
A 2020-05-27T16:12:26.977687Z 2020-05-27 16:12:26.977 INFO 10 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
A 2020-05-27T16:12:27.413333Z 2020-05-27 16:12:27.413 INFO 10 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
A 2020-05-27T16:12:27.683594Z 2020-05-27 16:12:27.683 INFO 10 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
A 2020-05-27T16:12:27.760810Z 2020-05-27 16:12:27.760 INFO 10 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [app-name:europe-west2:db-name] via unix socket.
A 2020-05-27T16:12:27.966435Z 2020-05-27 16:12:27.966 WARN 10 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected
2020-05-27 17:12:27.970 BST
2020-05-27 16:12:27.970 INFO 10 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
I've researched this issue and it seems that this happens when the runtime classpath is different the compile class path. Problem is that I can't reproduce it locally and I can't figure out if it's a dependency that's causing this.
Full stack trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:595)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1108)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:1215)
at com.turbochargedapps.basketballappinternalrest.BasketballAppInternalRestApplication.main (BasketballAppInternalRestApplication.java:21)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run (MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch (Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch (Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main (JarLauncher.java:52)
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected
at jnr.ffi.provider.jffi.AsmLibraryLoader.generateInterfaceImpl (AsmLibraryLoader.java:104)
at jnr.ffi.provider.jffi.AsmLibraryLoader.loadLibrary (AsmLibraryLoader.java:89)
at jnr.ffi.provider.jffi.NativeLibraryLoader.loadLibrary (NativeLibraryLoader.java:44)
at jnr.ffi.LibraryLoader.load (LibraryLoader.java:325)
at jnr.unixsocket.Native.<clinit> (Native.java:80)
at jnr.unixsocket.UnixSocketChannel.<init> (UnixSocketChannel.java:101)
at jnr.unixsocket.UnixSocketChannel.open (UnixSocketChannel.java:65)
at com.google.cloud.sql.core.CoreSocketFactory.connect (CoreSocketFactory.java:180)
at com.google.cloud.sql.postgres.SocketFactory.createSocket (SocketFactory.java:71)
at org.postgresql.core.PGStream.<init> (PGStream.java:73)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect (ConnectionFactoryImpl.java:93)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl (ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection (ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init> (PgConnection.java:211)
at org.postgresql.Driver.makeConnection (Driver.java:459)
at org.postgresql.Driver.connect (Driver.java:261)
at com.zaxxer.hikari.util.DriverDataSource.getConnection (DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection (PoolBase.java:358)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry (PoolBase.java:206)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry (HikariPool.java:477)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast (HikariPool.java:560)
at com.zaxxer.hikari.pool.HikariPool.<init> (HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection (HikariDataSource.java:112)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection (DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection (JdbcEnvironmentInitiator.java:180)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService (JdbcEnvironmentInitiator.java:68)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService (JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService (StandardServiceRegistryImpl.java:101)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService (AbstractServiceRegistryImpl.java:263)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService (AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService (AbstractServiceRegistryImpl.java:214)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices (DefaultIdentifierGeneratorFactory.java:152)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies (AbstractServiceRegistryImpl.java:286)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService (AbstractServiceRegistryImpl.java:243)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService (AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init> (InFlightMetadataCollectorImpl.java:176)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:118)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:1214)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:1245)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory (SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory (LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory (AbstractEntityManagerFactoryBean.java:391)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet (AbstractEntityManagerFactoryBean.java:378)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet (LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods (AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1792)
build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0'
}
}
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
}
apply plugin: 'com.google.cloud.tools.appengine'
appengine {
deploy {
appengine.deploy.version = "GCLOUD_CONFIG"
appengine.deploy.projectId = "GCLOUD_CONFIG"
}
}
group = 'com.group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
ext {
set('snippetsDir', file("build/generated-snippets"))
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compile project(':project-core-submodule')
compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.0.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.springframework.security:spring-security-test'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
compile 'io.jsonwebtoken:jjwt-api:0.11.1'
runtime 'io.jsonwebtoken:jjwt-impl:0.11.1',
// Uncomment the next line if you want to use RSASSA-PSS (PS256, PS384, PS512) algorithms:
//'org.bouncycastle:bcprov-jdk15on:1.60',
'io.jsonwebtoken:jjwt-jackson:0.11.1' // or 'io.jsonwebtoken:jjwt-gson:0.11.1' for gson
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-sql-postgresql'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
outputs.dir snippetsDir
useJUnitPlatform()
}
asciidoctor {
inputs.dir snippetsDir
dependsOn test
}
Any ideas?
Turns out it was Google Guava that was causing this issue - I simply removed the dependency from my build.gradle file, did gradle clean build and then redeployed!
I'm having an issue while using Elastic4S in a Scala project. The following error is thrown :
java.lang.NoSuchMethodError:
com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper.$init$(Lcom/fasterxml/jackson/module/scala/experimental/ScalaObjectMapper;)V
Followed by :
java.lang.NoClassDefFoundError: Could not initialize class
com.sksamuel.elastic4s.json.JacksonSupport$
Here are the dependencies used :
"com.sksamuel.elastic4s" %% "elastic4s-core" % "6.7.3",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "6.7.3",
"com.github.swagger-akka-http" %% "swagger-akka-http" % "2.0.4",
"com.github.swagger-akka-http" %% "swagger-scala-module" % "2.0.5",
...
),
assemblyMergeStrategy in assembly := { _ => MergeStrategy.first }
And the only bit of code launched from Elastic4s is in this method :
def testClusterUp(log: LoggingAdapter): Unit = {
val response: Response[NodeInfoResponse] = client.execute(
nodeInfo()
).await
if (response.isError) {
log.error(s"[ERROR]-[ELASTICSEARCH] $response")
throw new ExceptionInInitializerError(s"an error occurred during Elastic connector initialization : ${response.error}")
} else if (response.isSuccess) {
log.info("Cluster started successfully !")
}
}
Any help would be appreciated
There seem to be some other dependencies that are covering this one. For eg, the swagger-akka-http uses another version of jackson-scala-module and can't be included along without some tweaking in the build.sbt. Here would be the configuration to put in such case :
("com.github.swagger-akka-http" %% "swagger-akka-http" % "2.0.4") excludeAll(ExclusionRule(organization = "com.fasterxml.jackson.module")),
("com.github.swagger-akka-http" %% "swagger-scala-module" % "2.0.5") excludeAll(ExclusionRule(organization = "com.fasterxml.jackson.module")),
see more about sbt dependencies' exclusion rules here :
https://www.scala-sbt.org/release/docs/Library-Management.html#Exclude+Transitive+Dependencies
I have the following application.conf
mysql {
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://myserver:3306/mydb"
user = "foo"
password = "bar"
keepAliveConnection = true
connectionPool = enabled
}
when I do Database.forConfig("mysql") I get an exception
java.lang.ClassNotFoundException: enabled
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:17)
at slick.jdbc.JdbcDataSource$.loadFactory$1(JdbcDataSource.scala:37)
at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:46)
at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig(JdbcBackend.scala:288)
at slick.jdbc.JdbcBackend$DatabaseFactoryDef.forConfig$(JdbcBackend.scala:285)
at slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33)
at com.abhi.CodeGen$.delayedEndpoint$com$abhi$CodeGen$1(CodeGen.scala:25)
at com.abhi.CodeGen$delayedInit$body.apply(CodeGen.scala:15)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
If I change my config to
mysql {
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://myserver:3306/mydb"
user = "foo"
password = "bar"
keepAliveConnection = true
connectionPool = disabled
}
Then everything works.
But why do I get this wierd error message if I try to establish a connection with connection pool enabled?
Edit: This is my build.sbt
"com.typesafe.slick" %% "slick" % "3.2.0",
"com.typesafe.slick" %% "slick-codegen" % "3.2.0",
"mysql" % "mysql-connector-java" % "5.1.38",
"com.zaxxer" % "HikariCP" % "2.6.3"
Probably you haven't dependency in classpath for some jar with pool implementation, such as Hikari. Possible duplicate of Setting connectionPool crashes Slick 3.0
I am new to play framework. I need to create a soap service in play framework using java. I followed this article but was not able to run the application - activator/play version - 2.5.4
While accessing the service I got this error.
[warn] o.s.c.s.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.transport.play.CxfController#0' defined in class path resource [cxf.xml]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.cxf.transport.play.CxfController$]: Factory method 'getInstance' threw exception; nested exception is java.lang.AbstractMethodError: org.apache.cxf.transport.play.CxfController$.play$api$mvc$Results$_setter_$TooManyRequests_$eq(Lplay/api/mvc/Results$Status;)V
[error] application -
! #714g94j1n - Internal server error, for (GET) [/service/hello] ->
play.api.PlayException: Cannot init the Global object[Error creating bean with name 'org.apache.cxf.transport.play.CxfController#0' defined in class path resource [cxf.xml]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.cxf.transport.play.CxfController$]: Factory method 'getInstance' threw exception; nested exception is java.lang.AbstractMethodError: org.apache.cxf.transport.play.CxfController$.play$api$mvc$Results$_setter_$TooManyRequests_$eq(Lplay/api/mvc/Results$Status;)V]
at play.api.GlobalSettings$.apply(GlobalSettings.scala:229)
at play.api.inject.guice.GuiceApplicationBuilder$$anonfun$1.apply(GuiceApplicationBuilder.scala:99)
at play.api.inject.guice.GuiceApplicationBuilder$$anonfun$1.apply(GuiceApplicationBuilder.scala:99)
at scala.Option.getOrElse(Option.scala:121)
at play.api.inject.guice.GuiceApplicationBuilder.applicationModule(GuiceApplicationBuilder.scala:99)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:158)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:155)
My codes:
Build.sbt:
name := "play-cxf-hello"
version := "1.0-SNAPSHOT"
scalaVersion := "2.11.7"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
libraryDependencies += "org.springframework" % "spring-context" % "4.3.2.RELEASE"
libraryDependencies += "eu.imind.play" %% "play-cxf_play24" % "1.2.1"
libraryDependencies += "org.apache.cxf" % "cxf-rt-bindings-soap" % "3.1.7"
libraryDependencies += "org.apache.cxf" % "cxf-rt-frontend-jaxws" % "3.1.7"
plugins.sbt:
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.4")
applicationContext.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
">
<!-- Import Apache CXF configuration and Play! transport plugin. -->
<import resource="classpath:cxf.xml"/>
<!-- Define Hello World endpoint. It will be available at http://localhost:9000/service/hello -->
<jaxws:endpoint name="helloWorld"
transportId="http://schemas.xmlsoap.org/soap/http"
address="/service/hello"
implementor="services.hello.HelloWorldImpl"/>
</beans>
Global.java:
public class Global extends GlobalSettings {
protected ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
#Override
public void onStart(Application app) {
ctx.start();
}
#Override
public void onStop(Application app) {
ctx.stop();
}
}
Can anybody advice me on this?
So I'm trying to modify one of the typesafe activator templates to use an SQLite database instead of the built in H2 one. Here is the original template https://github.com/playframework/playframework/tree/master/templates/play-scala-intro
What I've done is to change the application.conf file to have these lines:
slick.dbs.default.driver=slick.driver.SQLiteDriver
slick.dbs.default.db.driver=org.sqlite.JDBC
slick.dbs.default.db.url="jdbc:sqlite:/home/marcin/play-scala-intro/people.db"
Of course I also created the file itself (just did touch people.db). Then if I start my application I am getting the following error:
[info] ! #6ooe822f0 - Internal server error, for (GET) [/] ->
[info]
[info] play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
[info] at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
[info] at play.api.Configuration.reportError(Configuration.scala:829) ~[play_2.11-2.4.6.jar:2.4.6]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:93) ~[play-slick_2.11-1.1.1.jar:1.1.1]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81) ~[play-slick_2.11-1.1.1.jar:1.1.1]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80) ~[play-slick_2.11-1.1.1.jar:1.1.1]
I was looking for some examples how to set it up like here
https://groups.google.com/forum/#!msg/scalaquery/07JBbnZ5VZk/7D1_5N4uGjsJ
or here:
https://github.com/playframework/play-slick
but they weren't similar enough to my code and since I'm new to all this I couldn't really figure out how to use them. Help appreciated, thanks!
[EDIT]:
following a suggestion from the comment I added "$" at the end of the driver name, to that what's in the conf file now looks like this:
slick.dbs.default.driver=slick.driver.SQLiteDriver$
slick.dbs.default.db.driver=org.sqlite.JDBC
slick.dbs.default.db.url="jdbc:sqlite:/home/marcin/play-scala-intro/people.db"
That works in the sense that another error comes up:
[info] Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
[info] at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441) ~[HikariCP-java6-2.3.7.jar:na]
[info] at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413) ~[HikariCP-java6-2.3.7.jar:na]
[info] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_66]
Yes, this is quite old question, but maybe the answer can be useful for someone.
All the works is based upon the example presented here:
https://developer.lightbend.com/start/?group=play&project=play-samples-play-scala-slick-example
I've successfully run SQLite database with Scala/Play/Slick performing the following steps:
build.sbt file:
lazy val root = (project in file("."))
.enablePlugins(PlayScala)
.settings(
name := """Application""",
version := "2.8.x",
scalaVersion := "2.13.1",
libraryDependencies ++= Seq(
guice,
"org.playframework.anorm" %% "anorm" % "2.6.5",
"com.typesafe.play" %% "play-slick" % "5.0.0",
"com.typesafe.play" %% "play-slick-evolutions" % "5.0.0",
"org.xerial" % "sqlite-jdbc" % "3.31.1",
specs2 % Test,
),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-Xfatal-warnings"
)
)
application.conf
slick.dbs.default.profile="slick.jdbc.SQLiteProfile$"
slick.dbs.default.db.profile="slick.driver.SQLiteDriver"
slick.dbs.default.db.url="jdbc:sqlite:/mnt/comments.db"
slick.dbs.default.db.driver=org.sqlite.JDBC
Please note, that it also works in the case for the relative path:
slick.dbs.default.profile="slick.jdbc.SQLiteProfile$"
slick.dbs.default.db.profile="slick.driver.SQLiteDriver"
slick.dbs.default.db.url="jdbc:sqlite:./comments.db"
slick.dbs.default.db.driver=org.sqlite.JDBC
Play Evolution also works:
play.evolutions {
db.default.enabled = true
}
I have play, slick, SQLite project: https://github.com/aukgit/scala-open-real-time-bidding-rtb
It also has a repository pattern.
Please check out https://github.com/aukgit/scala-open-real-time-bidding-rtb/releases/tag/v0.0.5
To give an example of how slick works with SQLite:
import slick.jdbc.SQLiteProfile.api._ // must import
lazy val db = Database.forURL(url = AbsoluteDatabasePath)
Repository pattern for slick
https://github.com/aukgit/scala-open-real-time-bidding-rtb/tree/6bf6beb6adb93b83cba49085d2d33269502189e1/app/shared/com/repository
You may download the repo in that release and run it using SBT
run sbt
or open using IntelliJ IDEA
Routers example of Play (https://github.com/aukgit/scala-open-real-time-bidding-rtb/blob/6bf6beb6adb93b83cba49085d2d33269502189e1/app/controllers/controllerRoutes/routerGeneric/RtbServiceBasicRouter.scala)
class RtbServiceBasicRouter #Inject()(
controller : RequestSimulatorServiceApiController)
extends SimpleRouter {
val routingActionWrapper : ControllerGenericActionWrapper = ControllerGenericActionWrapper(
ControllerDefaultActionType.Routing)
override def routes : Routes = {
try {
case GET(p"/serviceName") | GET(p"/") =>
controller.getServiceName()
case GET(p"/commands") | GET(p"/available-commands") | GET(p"/routes") =>
controller.getAvailableCommands()
case GET(p"/bannerRequest") =>
controller.getBannerRequestSample()
} catch {
case e : Exception =>
controller.handleError(e, routingActionWrapper)
throw e
}
}
}
Add routes controller to the routes (https://github.com/aukgit/scala-open-real-time-bidding-rtb/blob/6bf6beb6adb93b83cba49085d2d33269502189e1/conf/routes)
-> /services/v1/rtbSimulateService controllers.controllerRoutes.routerGeneric.RtbServiceBasicRouter
SBT Packages:
https://github.com/aukgit/scala-open-real-time-bidding-rtb/blob/6bf6beb6adb93b83cba49085d2d33269502189e1/build.sbt
Recommended packages for Sqlite in SBT:
"org.joda" % "joda-convert" % "2.2.1", // for time convert
"com.github.tototoshi" %% "slick-joda-mapper" % "2.4.2", // 2.4 doesn't work
"joda-time" % "joda-time" % "2.7",
"org.xerial" % "sqlite-jdbc" % "3.30.1", // sqlite driver
Slick Packages if you want to integrate :
"com.typesafe.slick" %% "slick" % "3.3.2",
"com.typesafe.slick" %% "slick-codegen" % "3.3.2", // for generating Table schema for sqlite db
Example for sqlite db to Table Schema generate (Database First Approach) [https://github.com/aukgit/scala-open-real-time-bidding-rtb/blob/6bf6beb6adb93b83cba49085d2d33269502189e1/app/shared/com/ortb/executors/DatabaseEngineCodeGenerator.scala] :
slick.codegen.SourceCodeGenerator.run(
profile = databaseGenerateConfig.profile,// "slick.jdbc.SQLiteProfile",
jdbcDriver = databaseGenerateConfig.jdbcDriver, //"org.sqlite.JDBC",
url = databaseGenerateConfig.compiledDatabaseUrl, //
// "jdbc:sqlite:D:\\PersonalWork\\Github\\scala-rtb-example\\src\\main\\resources\\openRTBSample.db",
outputDir = databaseGenerateConfig.compiledOutputDir, //
// "D:\\PersonalWork\\Github\\scala-rtb-example\\src\\main\\scala\\com\\ortb\\persistent\\schema",
pkg = databaseGenerateConfig.pkg,
user = None,
password = None,
ignoreInvalidDefaults = true,
outputToMultipleFiles = false
)