小编Ser*_*lvo的帖子

无法从SLF4J加载类"org.slf4j.impl.StaticLoggerBinder"消息错误

我正在使用Akka和Akka-http开发一个简单的服务器.

当我在IntelliJ中运行应用程序时,我总是在stdout中收到以下错误消息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Run Code Online (Sandbox Code Playgroud)

我在build.gradle中有以下依赖项:

compile 'org.scala-lang:scala-library:2.12.1'
compile 'com.typesafe.akka:akka-actor_2.12:2.4.17'
compile 'com.typesafe.akka:akka-stream_2.12:2.4.17'
compile 'com.typesafe.akka:akka-http_2.12:10.0.4'
compile 'com.typesafe.akka:akka-http-spray-json_2.12:10.0.4'
compile 'com.typesafe.akka:akka-slf4j_2.12:2.4.17'
Run Code Online (Sandbox Code Playgroud)

我有app.conf,如下所示:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "INFO"
  stdout-loglevel = "INFO"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
  ...
}
Run Code Online (Sandbox Code Playgroud)

最后,我正在使用这样的Logging:

object HttpServer extends App with JsonSupport {
  override def main(args: Array[String]): Unit = {

  val config = ConfigFactory.load()

  implicit val system = ActorSystem(config.getString("application.actor-system"))
  implicit val materializer = ActorMaterializer() …
Run Code Online (Sandbox Code Playgroud)

log4j scala slf4j akka

10
推荐指数
1
解决办法
5243
查看次数

在 Python3 中运行 unittest 导入错误

我在 Python 3.6 中导入文件时遇到问题。我的目录树如下所示:

project/
    app/
    ??? __init__.py
    ??? a.py
    ??? b.py
    test/
    ??? __init__.py
    ??? test_a.py
    ??? test_b.py
Run Code Online (Sandbox Code Playgroud)

它使用以下导入语句在我的应用程序中工作(但是,没有工作测试)b.py

from a import *
Run Code Online (Sandbox Code Playgroud)

但是,它在我的应用程序中不起作用(但是,可以进行测试)在b.py以下内容中使用另一个:

from .a import *
Run Code Online (Sandbox Code Playgroud)

所以,我选择from a import *。像python3 -m unittest我一样执行测试总是出现以下错误:

E.
======================================================================
ERROR: tests.test_cell (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_cell
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
  File "/Users/serrodcal/Repositories/project/tests/test_b.py", line …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-unittest

5
推荐指数
1
解决办法
9859
查看次数

在WSO2 ESB API资源中映射可选查询参数

我必须映射查询参数以将请求发送到WSO2 ESB中API资源中的端点。

这些查询参数是可选的。例如,以下是对资源的调用示例:

http://server:port/service?q1={q1}
http://server:port/service?q2={q2}&q3={q3}
Run Code Online (Sandbox Code Playgroud)

我需要一个资源来执行此操作。

我怎样才能做到这一点?

基本上,我必须在请求中读取查询参数,并将其放入对端点uri的调用中。

wso2 wso2esb

4
推荐指数
1
解决办法
1840
查看次数

从WSO2 ESB API中的SynapseXPath变量获取URI VAR

我想从请求中获取URI VAR值,以便在WSO2 ESB API资源中的switch中调用正确的大小写,如下所示:

<api name="apk" context="/apk"><resource methods="GET" uri-
template="/apk/{appName}"><inSequence><header name="App" 
scope="transport" action="remove"/><switch source="get-
property('uri.var.appName')"><case regex="BEBE"><send><endpoint><http 
method="GET" uri-template="http://localhost/apk/Bebe.apk></http>
</endpoint></send></case><case regex="CITAS"><send><endpoint><http 
method="GET" uri-template="http://localhost/apk/Citas.apk></http>
</endpoint></send></case></switch></inSequence></resource></api>
Run Code Online (Sandbox Code Playgroud)

在开关中,source="get-property('uri.var.appName')"它是不正确的.

我可以使用$urlSynapseXpath 这样的值来获得这个值$url吗?

wso2 wso2esb

3
推荐指数
1
解决办法
1724
查看次数

如何使用PowerMock模拟FileInputStream?

我正在尝试模拟FileInputStream,但是我无法让编译器在测试执行中使用模拟(总是得到FileNotFoundException)。

我创建了一个使用FileInputStream的简单类:

public class Class1 {

    public Class1() { }

    public boolean method1() {
        try {
            FileInputStream fileInputStream = new FileInputStream("file.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
Run Code Online (Sandbox Code Playgroud)

我创建了一个简单的测试,如下所示:

@RunWith(PowerMockRunner.class)
@PrepareForTest(FileInputStream.class)
public class Class1Test {

    @Test
    public void method1Test() throws Exception {

        Class1 class1 = new Class1();

        FileInputStream fileInputStreamMock = mock(FileInputStream.class);

        whenNew(FileInputStream.class).withAnyArguments().thenReturn(fileInputStreamMock);

        boolean expected = true;
        boolean actual = class1.method1();

        assertEquals(expected, actual);

    }

}
Run Code Online (Sandbox Code Playgroud)

这里使用的依赖项是:

<dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.7.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java unit-testing powermock

1
推荐指数
1
解决办法
565
查看次数