Comments (4)
As a workaround, could you try wrapping your onStart code in something that sets the context classloader to application.classloader?
from playframework.
I have found the source of an exception. When I define
object SomeObject {
lazy val db = Database.forDataSource(DB.getDataSource())
// usage of 'db'
// ...
}
and simply run application, everything is "fine" - database connection is retrieved from datasource and used until application shutdown. When I run functional tests: first test loads SomeObject, initializes session, does some work and exits. Second test loads SomeObject and reuses session which is expired (datasource is already closed).
Is it a bug or a feature of framework to reuse static objects?
This is why
If I replace this code with the method call of some instance of some class
helped.
Changing lazy val db = ...
to def db = ...
fixes the problem.
Is it fine to initialize slick's session this way on every request?
Also, I have additional tests that doesn't use Play's FakeApplication but communicate with database directly (via Database.forURL("jdbc:postgresql://localhost/test", ...)
I get SQLException: No suitable driver found for jdbc:postgresql://localhost/test (DriverManager.java:190)
if at least one functional test was executed before. I can rewrite them to use "fakes" as a workaround but wondering why does it happen.
P.S. @jroper Please point out some tutorial/explanation about Play's context class loader (is your suggestion is still relevant regarding information above?).
from playframework.
The context classloader is a JVM thing, not a Play thing, it's the classloader attached to the current running thread, and I believe it's what JDBC uses to locate SQL drivers. Setting it looks something like this:
val old = Thread.current().getContextClassLoader()
try {
Thread.current().setContextClassLoader(application.classloader())
// Your code here
} finally {
Thread.current().setContextClassLoader(old)
}
from playframework.
Caching a database session statically is not something that should ever be done. You should update it to def.
from playframework.
Related Issues (20)
- Caffeine cache API has inconsistent behavior with differing types and between sync/async HOT 1
- play hangs on console interacton when using jblas library HOT 4
- 2.9 with Scala 2.13 not supporting pack4j 6.00 dependency :Jackson Data-bind 2.15.x
- Documentation spelling fix HOT 3
- Scala 3.3.2: class file ... is broken, reading aborted with `class java.util.NoSuchElementException` `contextual$` HOT 9
- Replace `3.0.x` with next version HOT 5
- SSL certificate for www.playframework.com is expired HOT 2
- Search in documentation does not work HOT 1
- Support for Partitioned cookie attribute (AKA CHIPS) / make cookies more flexibel HOT 1
- Asset changes in subprojects HOT 2
- Recommend Scala Metals + VSCode as an IDE on this page: https://www.playframework.com/documentation/2.9.x/IDE HOT 1
- Timeout issue when using AsyncCacheApi and custom http filter HOT 2
- [2.8.20] CVE-2023-44487 in akka-http-core HOT 1
- Support for Application Secret rotation
- play 2.9 is trying to fetch guice-6.0.0-no_aop jar, caused not found error HOT 6
- Play gradle plugin fails to create playRun task when no compileScala task found in a project
- Dependency Dashboard
- Apache Pekko doesn't support autogenerated TLS certs HOT 1
- Application secret from env variable does not work HOT 3
- UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playframework.