我正在运行Java Play框架版本v2.6.1并使用Ebean进行持久化.我的目的是使用play2-memcached插件获取bean缓存.
到目前为止我做了什么?
memcached
在localhost上并启用详细日志记录.ehcache
用cacheApi
in libraryDependencies
in 替换了依赖build.sbt
(我假设,应该完全删除Ehcache)."com.github.mumoshu" %% "play2-memcached-play26" % "0.9.0",
到libraryDependencies
在build.sbt
"Spy Repository" at "http://files.couchbase.com/maven2",
到resolvers
在build.sbt
play.modules.disabled += "play.api.cache.ehcache.EhCacheModule"
play.modules.enabled+="com.github.mumoshu.play2.memcached.MemcachedModule"
play.cache.defaultCache=default
play.cache.bindCaches=["db-cache", "user-cache", "session-cache"]
memcached.host="127.0.0.1:11211"
Serializable
,还添加了@com.avaje.ebean.annotation.Cache
注释.什么有用?
Entity.find.byId(id)
结果SQL 加载实体SELECT
.使用不同的请求结果再次加载它没有SQL语句.com.github.mumoshu
加载了与缓存相关的类.什么不起作用?
netstat -na | …
我对使用Play的内容安全策略有疑问!框架(2.6).
我已经为项目添加了一个外部库来绘制图表,javascript文件在项目中,图表渲染得很好.
我遇到的问题是我的控制台左右喷出错误.这是我不断得到的错误:
拒绝应用内联样式,因为它违反了以下内容安全策略指令:"style-src'self'".要么是'unsafe-inline'关键字,要么是哈希('sha256-GPjBVmsZjSEoackW5SF7HKgSHcUUBqf1/TJwOl3Co7Y ='),要么是nonce('nonce -...')来启用内联执行.
在搜索如何解决这个问题的过程中,我遇到了一些内容,例如在HTML中包含一个元标记,它在Play中没有做任何事情.我也尝试将ContentSecurityHeader放在application.conf中,如下所述:https: //www.playframework.com/documentation/2.6.x/SecurityHeaders 这也没用.在开发我的项目时,我也遇到了关于default-src'self'的错误,我认为它将是相同类型的修复,而且它与配置有关,我没有做对.
如果有人不得不做这种类型的配置,我会喜欢关于如何正确配置我的应用程序的一些指示.
提前致谢!
configuration playframework content-security-policy playframework-2.6
使用play框架运行测试时,我遇到了进化问题
测试看起来像这样:
class TestFooController extends PlaySpec with GuiceOneServerPerSuite {
"foo endpoint should store some data" in {
val wsClient = app.injector.instanceOf[WSClient]
val url = s"http://localhost:$port/foo"
val requestData = Json.obj("foo" -> "bar")
val response = await(wsClient.url(url).post(requestData))
response.status mustBe OK
}
}
Run Code Online (Sandbox Code Playgroud)
数据库配置如下所示:
slick.dbs.default.driver="slick.driver.H2Driver$"
slick.dbs.default.db.driver="org.h2.Driver"
slick.dbs.default.db.url="jdbc:h2:mem:play"
Run Code Online (Sandbox Code Playgroud)
假设有一个创建表的进化脚本,foos
这个脚本在开发模式下工作正常.
运行测试时,抛出以下错误:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[JdbcSQLException: Table "foos" not found;
foos
无法找到该表,因此我假设尚未应用数据库演变.
然后我将数据库配置更改为在开发模式下使用的postgresql.
slick.dbs.default.driver = "slick.driver.PostgresDriver$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/foo-test"
slick.dbs.default.db.user = "user"
slick.dbs.default.db.password = "password"
Run Code Online (Sandbox Code Playgroud)
使用此配置,测试工作正常,数据存储在数据库中,因此数据库演进运行得很好. …
scala playframework playframework-evolutions play-slick playframework-2.6
当我执行sbt run
并刷新时,localhost:9000
将显示我的更改.如果我改变别的东西,保存我的项目并再次点击刷新localhost:9000
不会显示我的更改.如果我尝试sbt ~run
我可以看到sbt重新编译每次我更改文件并保存,但刷新localhost:9000
不显示任何更新.只有当我终止sbt进程并重新启动它时,才能看到我的更改.
我的设置:
Windows 8.1
玩2.6
sbt 1.0.2
斯卡拉2.12.3
Intellij 2017.2.5
我用 sbt assembly 命令构建了 play 框架项目 jar。当我使用 Java -jar "jarName.jar" 运行 jar 时,它会抛出错误“未提供根服务器路径”有什么建议吗?
java playframework ebean playframework-2.2 playframework-2.6
Posts Model
/*set many to one relation with Privacy_Level model*/
@ManyToOne//(fetch = FetchType.LAZY)
@JoinColumn(name = "privacy_level_id",referencedColumnName = "id", insertable = false, updatable = false)
public Privacy_Level privacy_level_t;
-------------------------------------------------------------------------------------------------------------
Privacy_Level Model
/*set one to many relation with Posts model*/
@OneToMany(mappedBy = "privacy_level_t")
public List<Posts> posts;
/*set many to one relation with Table_Status model*/
@ManyToOne
@JoinColumn(name = "status",referencedColumnName = "id", insertable = false, updatable = false)
public Table_Status table_status;
--------------------------------------------------------------------------------------------------------------
Table_Status Model
/*set many to one relation with Privacy_level table*/
@OneToMany(mappedBy = …
Run Code Online (Sandbox Code Playgroud) one-to-many many-to-one playframework ebean playframework-2.6
升级到 Play 2.6 后,我在日志中看到了很多“EntityStreamException: Entity stream truncation”。它看起来与客户端超时密切相关,这并不令人担忧。对于这种常见的 HTTP 事件,在应用程序代码中出现异常冒泡有点令人担忧,所以我担心这不仅仅是客户端超时。
akka.http.scaladsl.model.EntityStreamException: Entity stream truncation
at akka.http.impl.engine.parsing.HttpMessageParser$$anonfun$1.applyOrElse(HttpMessageParser.scala:321)
at akka.http.impl.engine.parsing.HttpMessageParser$$anonfun$1.applyOrElse(HttpMessageParser.scala:319)
at akka.stream.impl.fusing.Collect$$anon$6.$anonfun$wrappedPf$1(Ops.scala:217)
at akka.stream.impl.fusing.SupervisedGraphStageLogic.withSupervision(Ops.scala:178)
at akka.stream.impl.fusing.Collect$$anon$6.onPush(Ops.scala:219)
at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:515)
at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:478)
at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:374)
at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588)
at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:474)
at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:563)
at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:730)
at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:745)
at akka.actor.Actor.aroundReceive(Actor.scala:517)
at akka.actor.Actor.aroundReceive$(Actor.scala:515)
at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:655)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:592)
at akka.actor.ActorCell.invoke(ActorCell.scala:561)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
at akka.dispatch.Mailbox.run(Mailbox.scala:225)
at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Run Code Online (Sandbox Code Playgroud) 尝试在Scala中的Play 2.6中测试控制器时,我得到一个空指针异常.这是对OK响应的测试:
class ApplicationControllerSpec extends PlaySpec
with MockitoSugar with ScalaFutures {
val mockOrchestrator = mock[ApplicationOrchestrator]
val mockCC = mock[ControllerComponents]
val controller = new ApplicationController(mockOrchestrator, mockCC)
val method = controller.home()(FakeRequest())
assert(status(method) == 200)
}
Run Code Online (Sandbox Code Playgroud)
这是我正在测试的控制器:
class ApplicationController @Inject()
(orchestrator: ApplicationOrchestrator, cc: ControllerComponents)
extends AbstractController(cc) with I18nSupport {
def home(): Action[AnyContent] = Action {
implicit request: RequestHeader => //line 29
Ok(views.html.home())
}
}
Run Code Online (Sandbox Code Playgroud)
该错误看起来与隐式请求相关联,但我找不到解决方案.
日志输出是:
java.lang.NullPointerException was thrown.
java.lang.NullPointerException
at controllers.ApplicationController.home(ApplicationController.scala:29)
我在 Play 2.6,使用 Java
我的控制器返回:
public Result xml() {
return Results.ok(new ByteArrayInputStream("<someXml />".getBytes()));
}
Run Code Online (Sandbox Code Playgroud)
我想在测试中解析结果:
Result result = new MyController().xml();
play.test.Helpers.contentAsString(result)
Run Code Online (Sandbox Code Playgroud)
这抛出
failed: java.lang.UnsupportedOperationException: Tried to extract body from a non strict HTTP entity without a materializer, use the version of this method that accepts a materializer instead
Run Code Online (Sandbox Code Playgroud)
如何在测试中检索从输入流发出的结果的内容?
playframework ×10
scala ×4
ebean ×3
java ×3
akka ×1
akka-http ×1
akka-stream ×1
jwt ×1
many-to-one ×1
memcached ×1
one-to-many ×1
play-slick ×1
sbt ×1
unit-testing ×1