在Play框架中是否有默认捕获所有后备路由?如果是这样,我如何在我的路线文件中配置它?目前,有些网址我不希望用户给他们打电话,即使他们打电话,我也不希望出现错误页面,而是希望他们转到我的网络应用程序的登录页面!有没有办法在路由配置文件中执行此操作?
我正在为我的一个项目使用 Play2 Maven 插件,当我尝试使用 mvn play2:run 命令启动或运行我的项目时,我看到构建成功,但是当我尝试访问应用程序 url 时,我没有看到任何东西(可能是 404)。有什么想法是错的吗?
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0.0.0.0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
[success] Total time: 1 s, completed Mar 16, 2014 4:55:43 PM
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.855s
[INFO] Finished at: Sun Mar 16 16:55:43 CET 2014
[INFO] Final Memory: 11M/114M
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
它说按 Ctrl+D 停止服务器,但如何停止可能未运行的服务器?这是一个错误还是我做错了什么?
在以下代码段中,
trait MyType1; trait MyType2
import scala.concurrent.Promise
val p1 = Promise[Option[MyType1]]()
val p2 = Promise[MyType2]()
Run Code Online (Sandbox Code Playgroud)
我将p1和p2传递给另一个函数,在那里我使用一个成功的Future来完成Promise.调用此函数后,我尝试读取Promise中的值:
trait Test {
// get the Future from the promise
val f1 = p1.future
val f2 = p2.future
for {
someF1Elem <- f1
f1Elem <- someF1Elem
f2Elem <- f1Elem
} yield {
// do something with f1Elem and f2Elem
"..."
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我遇到了一些编译器问题.
Error:(52, 19) type mismatch;
found : Option[Nothing]
required: scala.concurrent.Future[?]
flElem <- someF1Elem
^
Run Code Online (Sandbox Code Playgroud)
IntelliJ没有显示任何错误,也没有显示任何错误,并且类型看起来是对齐的.但我不确定编译器为什么不开心!有线索吗?
我有一个演员,在其中使用context.become对状态进行了突变:这是代码段:
def stateMachine(state: State): Receive = {
case a => {
... do something
context.become(stateMachine(newState))
}
case b => {
... do something
sender ! state
}
case c => {
... do something
context.become(stateMachine(newState))
}
}
Run Code Online (Sandbox Code Playgroud)
我的IntelliJ说我的stateMachine(...)函数是递归的。这有问题吗?我应该担心吗?在上面的示例中,我的方法存在根本上的错误吗?
我在使用 SOAP WebServices 时遇到一个非常奇怪的错误。这里奇怪的是,客户端在测试服务器上工作正常,但在生产服务器上尝试时,它会失败并出现读取超时:
[com.ctc.wstx.exc.WstxLazyException] Read timed out
Run Code Online (Sandbox Code Playgroud)
甚至奇怪的是,当我在生产环境中使用相同的 SOAP 客户端代码库时,当在我的机器上针对生产 SOAP WebService 服务器本地运行时,它运行得非常好。仅在我们的生产客户端环境中,生产 SOAP WebService 服务器才会出现此异常。我对此完全一无所知,在过去的 4 个小时里,我一直试图与我的一位网络同事找出这个问题的根源,但没有成功。有什么线索吗?
我正在使用 Apache CXF!
我正在阅读并通过使用类型类来解决这个问题,并且我从Shapeless指南中找到了这种定义类型类的方法:
所以这里是一个例子:
object CsvEncoder {
// "Summoner" method
def apply[A](implicit enc: CsvEncoder[A]): CsvEncoder[A] =
enc
// "Constructor" method
def instance[A](func: A => List[String]): CsvEncoder[A] =
new CsvEncoder[A] {
def encode(value: A): List[String] =
func(value)
}
// Globally visible type class instances
}
Run Code Online (Sandbox Code Playgroud)
我不明白需要申请方法吗?在上面这个背景下它做了什么?
稍后,该指南描述了如何创建类型类实例:
implicit val booleanEncoder: CsvEncoder[Boolean] =
new CsvEncoder[Boolean] {
def encode(b: Boolean): List[String] =
if(b) List("yes") else List("no")
}
Run Code Online (Sandbox Code Playgroud)
实际上缩写为:
implicit val booleanEncoder: CsvEncoder[Boolean] =
instance(b => if(b) List("yes") else List("no"))
Run Code Online (Sandbox Code Playgroud)
所以现在我的问题是,这是如何工作的?我没有得到的是需要申请方法?
编辑:我发现了一篇博客文章,描述了创建类型类的步骤,如下所示:
我有一个如下所示的 Dockerfile:
# Pull base image
FROM openjdk:8
ENV SCALA_VERSION 2.12.2
ENV SBT_VERSION 0.13.15
# Scala expects this file
RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release
# Install Scala
## Piping curl directly in tar
RUN \
curl -fsL http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
# Install sbt
RUN \
curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get …Run Code Online (Sandbox Code Playgroud) 我正在使用 Rust 1.35.0 来尝试一些 Rust 示例,但我无法编译它,因为我不断收到以下消息:
error[E0463]: can't find crate for `core`
Run Code Online (Sandbox Code Playgroud)
我跑了rustc --explain E0463,我看到以下消息:
You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.
Run Code Online (Sandbox Code Playgroud)
这是我的 Cargo.toml:
[package]
name = "sensor-node"
version = "0.1.0"
authors = ["joesan <email@gmail.com>"]
edition = "2018"
[dependencies]
dwm1001 = "0.1.0"
panic-halt = "0.2.0" …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Zola 生成的静态站点,我正在使用 GitHub Actions 构建我的静态站点并将其发布到我的存储库的gh-pages分支中。我还使用 gh-pages 分支将我的项目配置为通过 GitHub 页面提供服务。
我面临的问题是,一旦我的 GitHub 操作构建新版本并将其推送到 gh-pages 分支,GitHub 设置中的自定义域设置就会重置。
以下是我在 GitHub 操作中构建并推送到 TARGET_BRANCH (gh-pages) 分支的操作:
- name: Commit and push to target branch
run: |-
git config --global user.email "workflow-bot@mydomain.com"
git config --global user.name "workflow-bot"
git checkout --orphan $TARGET_BRANCH
rm -rf .github/
mv public ..
rm -rf *
mv ../public/* .
touch .nojekyll
touch README.md
echo 'https://www.bigelectrons.com - SITE GENERATED USING ZOLA' > README.md
git add .
git commit -m "generated …Run Code Online (Sandbox Code Playgroud) 我有一个项目,正在使用 GitHub Actions 进行 CI/CD。我有一个 shell 脚本,我想从我的 Actions yml 中注入环境变量。这是我到目前为止所拥有的:
- name: docker-push
env:
USER: joesan
SOME_GITHUB_REPO_NAME: github-repo-name
GH_REPO: github.com/$USER/$SOME_GITHUB_REPO_NAME
run: |
echo "Running sbt assembly"
echo $GITHUB_REF
echo "Pushing tag into Docker Registry"
sh ./scripts/tag_deployment.sh
Run Code Online (Sandbox Code Playgroud)
在 tag_deployment.sh 中,我尝试使用这些变量:
....
....
git clone https://${GH_REPO}
cd "${SOME_GITHUB_REPO_NAME}"
....
....
Run Code Online (Sandbox Code Playgroud)
但我看到当操作运行时它不会打印设置的内容!
Cloning into '$SOME_GITHUB_REPO_NAME'...
fatal: unable to access 'https://github.com/$USER/$SOME_GITHUB_REPO_NAME/': The requested URL returned error: 400
Run Code Online (Sandbox Code Playgroud)
如何将这些环境变量正确注入到我的 shell 脚本中?