小编Flo*_*ain的帖子

在java中的同一类的“每个”方法之前执行一个函数

我在一个类中有几个方法需要将布尔值设置为 true 才能正确执行。

我可以if在每个方法中编写语句,但是如果我或其他人想要添加另一种方法,则不方便。我或他可以忘记支票。

java中有没有办法在类中的其他方法之前执行一个方法(就像JUnit所做的那样@BeforeEach)?

编辑:提出了许多非常有趣的技术/答案/概念。当我了解他们时,我会与他们取得联系。谢谢。

java

8
推荐指数
2
解决办法
1709
查看次数

错误:使用 npm 模块 - ssh2-sftp-client 连接到在 aws 上创建的 vsftpd 服务器时,所有配置的身份验证方法均失败

用于连接 vsftpd 服务器的代码

sftp.connect({

host: "3.6.75.65"

port: "22"

username: "ashish-ftp"

password: "*******"

})
.then(() => {

console.log("result")

})
.catch((err)=>{

console.log("error")

})
Run Code Online (Sandbox Code Playgroud)

我已经在 aws 中完成了用于文件传输的 VSFTPD 服务器的设置,并尝试使用 npm 模块 - ssh2-sftp-client 进行连接,它显示了下面给出的错误

Error: All configured authentication methods failed

at tryNextAuth (/home/ashish/addis/node_modules/ssh2/lib/client.js:392:17)

at SSH2Stream.onUSERAUTH_FAILURE (/home/ashish/addis/node_modules/ssh2/lib/client.js:599:5)

at emitTwo (events.js:126:13)

at SSH2Stream.emit (events.js:214:7)

at parsePacket (/home/ashish/addis-pianca/node_modules/ssh2-streams/lib/ssh.js:3930:10)

at SSH2Stream._transform (/home/ashish/addis-pianca/node_modules/ssh2-streams/lib/ssh.js:671:13)

at SSH2Stream.Transform._read (_stream_transform.js:186:10)

at SSH2Stream._read (/home/ashish/addis-pianca/node_modules/ssh2-streams/lib/ssh.js:253:15)

at SSH2Stream.Transform._write (_stream_transform.js:174:12)

at doWrite (_stream_writable.js:397:12)

at writeOrBuffer (_stream_writable.js:383:5)

at SSH2Stream.Writable.write (_stream_writable.js:290:11)

at Socket.ondata (_stream_readable.js:639:20)

at emitOne (events.js:116:13)

at …
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm

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

Pytest 装置不应该直接调用

我想在 conftest.py 中设置一个固定装置,并与我的所有测试共享它。但是,在以下最小示例上运行 pytest 时遇到以下错误:

ERROR at setup of test_test 
Fixture "pytest_runtest_setup" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
Run Code Online (Sandbox Code Playgroud)

conftest.py

import pytest
import os


@pytest.fixture
def pytest_runtest_setup():
    print("hello ? ---------------------------------")
Run Code Online (Sandbox Code Playgroud)

test.py

import pytest


def test_test():
    assert True
Run Code Online (Sandbox Code Playgroud)

pytest.ini

[pytest]
addopts = -rA -v -p no:faulthandler -W ignore::DeprecationWarning
Run Code Online (Sandbox Code Playgroud)

Pytest 启动时使用pytest test.py

没有任何地方直接调用fixture函数,甚至在示例测试中也没有使用它。那么为什么 pytest 会抛出这个问题以及如何在 conftest.py 中声明和使用固定装置?

环境:

  • Python 3.8.3
  • pytest-6.1.2

python pytest python-3.x

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

将缓冲区转换为可读字符串javascript

我收到一个JSON作为缓冲区。我想将其解析为可读或JSON对象。

但是,尽管使用了所有技术(JSON.stringify()toString('utf8'),我仍无法完成它。

这是我到目前为止所拥有的:

在此处输入图片说明

这就是它给我的:

在此处输入图片说明

如何将其转换为可读的内容?

javascript decoding protocol-buffers node.js

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

在带有 SonarQube 的 Java 中,如何修复“只应检查结果的符号”

我有以下代码行(其中“next”是 BigDecimal):

if (next.compareTo(maximum) == 1) {
    maximum = next;
}
Run Code Online (Sandbox Code Playgroud)

在相等比较时,SonarQube 给了我这个警告:

只应检查结果的符号。sonarqube-inject

它实际上是什么意思,我该如何解决?

java sonarqube

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

重置密码时避免"自动登录"

我正在开发一个Laravel项目.我不是原始的开发人员,所以如果我犯了错误,请原谅我并解释它是什么.

在这个项目中,我们有一个模块来请求一个新密码.当表单被提交时route('password.request'),用户被重定向到我认为隐藏在框架中的某个地方.

问题是当用户获得新密码时,他会自动登录并可以访问这些页面.但他不应该因为他没有管理权.

所以我尝试注销并将用户重定向到主页,没有任何运气.

有人可以解释为什么laravel(或"我",因为它们是我尚未探索的项目的某些部分)这样做以及如何解决这个问题?

reset.blade.php(请求新密码的表单)

form class="form-horizontal" role="form" method="POST" action="{{ route('password.request') }}">
    {{ csrf_field() }}

    <input type="hidden" name="token" value="{{ $token }}">
....
Run Code Online (Sandbox Code Playgroud)

我的自定义注销路线:

Route::get('/customLogout', 'Auth\LoginController@customLogout');
Run Code Online (Sandbox Code Playgroud)

resetPasswordController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods …
Run Code Online (Sandbox Code Playgroud)

php controller routes laravel

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

Go语言安装

我只是按照 golang (ubuntu 16) 的安装指南进行操作。我在 /etc/usr 中提取了存档,在 /home/user/.profile 中添加了 env 变量,我刚刚在 hello world 代码上测试了基本的 go 构建。

我收到以下错误:

The program 'go' is currently not installed. You can install it by typing: sudo apt install golang-go
Run Code Online (Sandbox Code Playgroud)

为什么它要求我(再次?)安装它?

installation go go-build

2
推荐指数
2
解决办法
2594
查看次数

无法访问 HBase Web UI

我正在关注HBase 的快速入门文档。

但是,我无法访问 HBase Web UI。

我尝试使用这些地址:

我尝试了不同的端口,因为文档说使用 60010,但快速入门说使用 16010。

这些都不起作用。

这是我的 hbase-site.xml

<configuration>
<property>
    <name>hbase.rootdir</name>
    <value>file:///home/hduser/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/home/hduser/zookeeper</value>
  </property>
  <property>
    <name>hbase.unsafe.stream.capability.enforce</name>
    <value>false</value>
    <description>
      Controls whether HBase will check for stream capabilities (hflush/hsync).

      Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
      with the 'file://' scheme, but be mindful of the NOTE below.

      WARNING: Setting this to false blinds you to potential data loss and
      inconsistent system …
Run Code Online (Sandbox Code Playgroud)

hadoop hbase

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

在 Nifi 中实现计数器作为流文件属性

使用Nifi,我想处理处理器的错误。

如果处理器将流文件发送到失败链接,我想将其发送回未能处理它的处理器x次。

为此,我想在流文件属性中实现一个计数器。但是,我面临两个问题

  • 如何检查流文件是否包含该counter属性?
  • counter如果属性存在的话如何增加?

到目前为止,我有以下流程:

电流

我被困在“更新计数器”处理器上。我不明白如何才能实现这一目标。

流文件第一次进来时该属性counter不存在。我想检查它是否存在,如果不存在,则将其添加到流文件中。当它在执行过程中稍后出现时,如果存在,我想增加它。这怎么可能?

apache-nifi

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

向maven添加依赖时出现问题

我有一个非常基本的 springboot 项目,具有以下 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>



    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

我想添加此依赖项:https://search.maven.org/artifact/org.apache.hive/hive-jdbc/3.1.2/jar

所以我添加了依赖项:

<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>3.1.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,当我的 pom.xml 中有此内容时,出现以下错误:

在解决构建路径错误之前无法构建项目 …

java pom.xml maven spring-boot

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