小编shh*_*hha的帖子

子对象上的 javax.validation.valid

我有一个简单的结构

public class Parent {
    @Size(min = 5, max = 10)
    String lastName;
    List<Child> childs;
}

public class Child {
    @Size(min = 5, max = 10)
    String firstName;
    @Size(min = 1, max = 18)
    Integer age;
}
Run Code Online (Sandbox Code Playgroud)

和一个有定义的方法

@ResponseBody
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces="application/json")
public RestResponse create(@RequestBody Parent object)
Run Code Online (Sandbox Code Playgroud)

它创建(并提供更新)父对象。

假设我想创建两个功能:

1) 创建工作副本 - 用户不必正确插入所有数据。

2)向我发送这些数据 - 在这个例子中,我想验证它们是否正确。

我发现有一种方法可以通过向方法定义中的参数添加 @Valid 注释来验证它,如下所示:

@ResponseBody
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces="application/json")
public RestResponse create(@RequestBody @Valid Parent object)
Run Code Online (Sandbox Code Playgroud)

但它只对父字段有效,跳过子字段。我可以在子列表上添加 @Valid 注释: …

java validation methods spring

6
推荐指数
3
解决办法
8651
查看次数

Sonarqube授权 - 当sonar.forceAuthentication启用时如何使用sonar-maven-plugin进行授权

我有默认配置的sonarqube 6.5.当sonar.forceAuthentication标志设置为false时,我可以通过下面给出的命令创建和分析项目.

mvn sonar:sonar -Dsonar.host.url=https://mySonarHost/sonar -Dsonar.login=mySonarUserKey

当我启用sonar.forceAuthentication参数(sonar.forceAuthentication = true)时,我无法分析项目.我总是得到maven错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project storm: Not authorized. Please check the properties sonar.login and sonar.password. -> [Help 1]

它不适用于默认管理员帐户,也不适用于创建的用户帐户(具有分析项目的权限).我也试过不使用用户密钥,但用户的登录名和密码(-Dsonar.login以及-Dsonar.passwordmaven配置),但它也不起作用.我试过使用不同的声纳版本(从4.5.7到5.6.6到最新的6.5,但我总是得到相同的结果).

在连接期间,我在access.log中收到了这样的消息:

IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/batch/index HTTP/1.1" 200 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"
IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/api/settings/values.protobuf HTTP/1.1" 401 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"
Run Code Online (Sandbox Code Playgroud)

我需要将sonar.forceAuthentication参数设置为true(只有受信任的用户才能访问它).

知道如何配置和访问带有凭证参数的maven的sonarqube吗?

authorization runner sonar-runner sonarqube sonarqube-scan

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