小编Men*_*ris的帖子

使用 MockHttpServletRequest 时出现 NoSuchMethodError - JUnit

当我尝试像这样实例化 MockHttpServletRequest 对象时出现以下错误: MockHttpServletRequest request = new MockHttpServletRequest();

java.lang.NoSuchMethodError: org.springframework.core.CollectionFactory.createLinkedMapIfPossible(I)Ljava/util/Map;在 org.springframework.mock.web.MockHttpServletRequest.(MockHttpServletRequest.java:107) 在 org.springframework.mock.web .MockHttpServletRequest.(MockHttpServletRequest.java:187)

我的Maven代码:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>groupId</groupId>
    <artifactId>Servlet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
    </properties>
    <dependencies>

        <!-- http://mvnrepository.com/artifact/org.springframework/spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.6.RELEASE</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/org.springframework/spring-mock -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-mock</artifactId>
            <version>2.0.8</version>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

iml文件中:

<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
          <root url="file://$MODULE_DIR$/web" relative="/" />
        </webroots>
        <sourceRoots />
      </configuration>
    </facet> …
Run Code Online (Sandbox Code Playgroud)

junit spring dependency-injection mockito maven

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

使用Spring Boot配置Swagger UI

我正在尝试使用Spring启动应用程序配置Swagger UI.虽然v2/api-docs似乎正在加载正确,但是http://localhost:8080/swagger-ui.html不会加载我带注释的REST API.

这是我有的:

pom.xml中:

...
<!--Swagger UI-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>
...
Run Code Online (Sandbox Code Playgroud)

SwaggerConfig.java

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

@Configuration
@EnableSwagger2
public class SwaggerConfig
{
    @Bean
    public Docket api()
    {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(regex("/.*"))
                .build().apiInfo(apiInfo());
    }

    private ApiInfo apiInfo()
    {
        ApiInfo apiInfo = new ApiInfo(
                "My Project's REST API",
                "This is a description of your API.", …
Run Code Online (Sandbox Code Playgroud)

spring swagger swagger-2.0

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

访客能否修改其访问的对象

当使用Visitor Pattern时visit(object)方法是否可以更新或修改其访问的对象,还是仅应将其用于执行某些计算并返回计算结果?

谢谢

java visitor

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

使用 node.js 加密验证签名

我正在尝试使用 AWS lambda 快速验证使用 sec256r1 创建的签名。

消息:“一些要签名的文本”

也用 sha256 进行了哈希处理

签名将采用 base64

encoding:MEYCIQCPfWhpzxMqu3gZWflBm5V0aetgb2/S+SGyGcElaOjgdgIhALaD4lbxVwa8HUUBFOLz+CGvIioDkf9oihSnXHCqh8yV
Run Code Online (Sandbox Code Playgroud)

公钥看起来像这样:

-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEXIvPbzLjaPLd8jgiv1TL/X8PXpJN
gDkGRj9U9Lcx1yKURpQFVavcMkfWyO8r7JlZNMax0JKfLZUM1IePRjHlFw==
-----END PUBLIC KEY-----
Run Code Online (Sandbox Code Playgroud)

澄清,

我正在尝试使用 lambda 来验证来自客户端的签名,并在需要时使用其公钥加密数据。

这是代码:

    const crypto = require('crypto');
    const verify = crypto.createVerify('SHA256');

    verify.write('some text to sign');
    verify.end();

    const l1 = "-----BEGIN PUBLIC KEY-----\n"
    const l2 = 
  "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEXIvPbzLjaPLd8jgiv1TL/X8PXpJNgDkGRj9U9Lcx1yKURpQFVavcMkfWyO8r7JlZNMax0JKfLZUM1IePRjHlFw=="

    const l3 = "\n-----END PUBLIC KEY-----"

    const publicKey = l1 + l2 + l3

    const signature = "MEYCIQCPfWhpzxMqu3gZWflBm5V0aetgb2/S+SGyGcElaOjgdgIhALaD4lbxVwa8HUUBFOLz+CGvIioDkf9oihSnXHCqh8yV";

    console.log(verify.verify(publicKey, signature));// Prints: true or false
Run Code Online (Sandbox Code Playgroud)

digital-signature public-key-encryption node.js

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

tabIndex 作为 CSS 属性?

我想弄清楚如何tabindex通过 css 使用 HTML 属性。

我特别想添加tabIndex=0到所有包含className='my-checkbox'.

这就是我所拥有的:

<div tabIndex="0" className="my-checkbox">
...
<div>
Run Code Online (Sandbox Code Playgroud)

由于 my<div className="my-checkbox">在我的应用程序中重复多次,我不想tabIndex每次都显式定义该属性;因此我正在寻找一种避免代码重复的方法。

如何tabIndex=0向所有div包含 a 的元素添加属性className="my-checkbox"

我尝试添加以下 css 规则,但这不起作用:

div .my-checkbox-img {
   tab-index: '0'
}
Run Code Online (Sandbox Code Playgroud)

这增加了一种tab-index似乎不具有功能性的风格;Google Chrome 调试器将其显示为unknown property.

在此输入图像描述

我尝试过nav-index但它似乎也已被弃用。

从三方面总结我的问题:

  1. 样式和属性有什么区别?我正在寻找比这个答案更详细的东西。
  2. html 属性与 css 属性(例如tabIndextotab-index等)有何关系?
  3. 如何tabIndex=0向所有div包含 a 的元素添加属性className="my-checkbox"

html css dom properties tabindex

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

Matlab - implay的默认大小窗口

我正在使用implay来播放我想要的一些帧,问题是弹出的窗口大小有点小,所以用户必须自己最大化它,有没有办法控制弹出窗口的大小?

matlab matlab-figure

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

自定义杰克逊反序列化通用抽象类

我在尝试反序列化以下类时遇到问题:

public class MetricValuesDto {

    private Map<MetricType, MetricValueDto<?>> metricValues;

    public MetricValuesDto() {
    }

    public MetricValuesDto(Map<MetricType, MetricValueDto<?>> metricValues) {
        this.metricValues = metricValues;
    }

    public Map<MetricType, MetricValueDto<?>> getMetricValues() {
        return metricValues;
    }

    public void setMetricValues(Map<MetricType, MetricValueDto<?>> metricValues) {
        this.metricValues = metricValues;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的通用抽象类:

public abstract class MetricValueDto<T> {

    private T value;
    private MetricTrend trend;

    public MetricValueDto(T value, MetricTrend trend) {
        this.value = value;
        this.trend = trend;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = …
Run Code Online (Sandbox Code Playgroud)

java serialization spring type-erasure jackson

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

无法在Mac上安装angular-cli

这可能是非常微不足道的,但是当我试图(不成功)安装angular-cli时,我正撞在墙上.

我在这里关注官方的angular-cli文档.

mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm -v
5.6.0
mkotsollariss-MacBook-Pro:~ mkotsollaris$ node -v
v8.9.4
Run Code Online (Sandbox Code Playgroud)

然后我运行npm install -g angular-cli,它给了我:

mkotsollariss-MacBook-Pro:~ mkotsollaris$ npm install -g angular-cli
npm WARN deprecated angular-cli@1.0.0-beta.28.3: angular-cli has been renamed to @angular/cli. Please update your dependencies.
npm WARN deprecated gulp-util@3.0.7: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN @angular/core@2.4.10 requires a peer of rxjs@^5.0.1 but none is …
Run Code Online (Sandbox Code Playgroud)

macos node.js npm angular-cli

3
推荐指数
4
解决办法
2万
查看次数

自定义DialogFragment中的View.OnClickListener

我正在尝试DialogFragment按照教程实现自定义.我的问题是我无法处理我的自定义视图的button.setOnClickListener事件.最奇怪的是我在.getText()按下按钮时没有问题,我找不到处理点击事件的方法.贝娄是我的代码:

SettingsDialogFragment.java

 public class SettingsDialogFragment extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.dialog_settings, null);

    final Button colorButton =(Button) view.findViewById(R.id.colorButton_dialogSettings);
    String s = colorButton.getText().toString();
    System.out.println("its working "+s);

    //NOT working
    colorButton.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            System.out.println("OnClick");
        }
    });

    // Inflate and set the layout for the dialog
    // Pass null as the …
Run Code Online (Sandbox Code Playgroud)

android android-view android-dialogfragment onclicklistener

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