小编Far*_*raz的帖子

没有覆盖纽约摩卡

即使测试用例通过,我也无法弄清楚为什么测试覆盖率是0。我在package.json中有一个脚本:

"nyctest": "node --max_old_space_size=4096 node_modules/nyc/bin/nyc.js --reporter=text mocha"
Run Code Online (Sandbox Code Playgroud)

当我跑步 npm run nyctest

我的测试通过了,但是覆盖率为0%。

在此处输入图片说明

以下是测试,文件正在测试:

test.js

var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
var application = require('../../../src/main/resources/static/js/components/app.js');

describe('sample return testing', function(){
    it('should return true', function(){
        application.sample.returnValue().should.equal(true);
    })
});
Run Code Online (Sandbox Code Playgroud)

app.js

const sample = {
    returnValue: function () {
        return true;
    }
};

module.exports = {sample};
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助。

mocha.js node.js istanbul

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

使用同步块的Java中的并发性未给出预期结果

下面是一个简单的java程序.它有一个名为"cnt"的计数器,它会递增,然后添加到名为"monitor"的List中."cnt"由多个线程递增,并且值被多个线程添加到"监视器".

在方法"go()"的末尾,cnt和monitor.size()应该具有相同的值,但它们不具有相同的值.monitor.size()确实有正确的值.

如果通过取消注释其中一个已注释的同步块来更改代码,并注释掉当前未注释的块,则代码会生成预期结果.此外,如果将线程计数(THREAD_COUNT)设置为1,则代码会生成预期结果.

这只能在具有多个真实核心的计算机上重现.

public class ThreadTester {

    private List<Integer> monitor = new ArrayList<Integer>();
    private Integer cnt = 0;
    private static final int NUM_EVENTS = 2313;
    private final int THREAD_COUNT = 13;

    public ThreadTester() {
    }

    public void go() {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                for (int ii=0; ii<NUM_EVENTS; ++ii) {
                    synchronized( monitor) {
                        synchronized(cnt) {        // <-- is this synchronized necessary?
                            monitor.add(cnt);
                        }
//                        synchronized(cnt) {
//                            cnt++;        // <-- why does moving …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading synchronized synchronized-block

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

@SpringBootConfiguration与@Configuration有什么区别?

@SpringBootConfiguration和之间有什么区别@Configuration?我找不到很多细节。

spring spring-boot

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

RestTemplate 拦截器

我目前正在尝试合并 aHandlerInterceptorAdapter但它没有被注册并且将它与其他答案进行比较很困难,因为每个人都在使用不同的东西。而且我知道 WebMvcConfigureAdapter 已被弃用,某些版本控制超出了我对项目范围的控制,请参阅下面的使用规范。

有人可以提供一些关于将拦截器与 RestTemplate(不是 ClientHttpRequestInterceptor)合并的指导。

主要的:

@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {

  public static void main(String[] args) {

   ApplicationContext ctx = SpringApplication.run(Application.class, args);

  }


  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {

    return applicationBuilder.sources(Application.class);

  }

  @Bean
  private RestTemplate restTemplate(){
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("redacted", 8080));

    SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    simpleClientHttpRequestFactory.setProxy(proxy);
    simpleClientHttpRequestFactory.setOutputStreaming(false);

    RestTemplate template = new RestTemplate();
    template.setErrorHandler(new MyResponseErrorHandler());

    return template;
  }
}
Run Code Online (Sandbox Code Playgroud)

拦截器:com.example.foo.config.request.interceptor

@Component
public class MyInterceptor extends HandlerInterceptorAdapter {

  @Override
  public boolean …
Run Code Online (Sandbox Code Playgroud)

java spring interceptor resttemplate

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

spring-boot-autoconfigure-processor 的目的?

目的是什么:

annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor"
Run Code Online (Sandbox Code Playgroud)

无论有没有它,我的应用程序都可以正常工作。我创建的薄罐子在依赖项目中也运行良好。

我问这个问题是因为当我将它包含在本地 build.gradle 中时,该行工作正常。但当我将其推送到云端时,我收到此错误:

在 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象上找不到参数 [org.springframework.boot:spring-boot-autoconfigure-processor] 的方法 commentProcessor()。

所以我想不要它。我没有看到对 Thin jar 或依赖项目有任何影响。

另外,此页面说当使用 Gradle 4.6 或更高版本时,我必须在 build.gradle 中使用annotationProcessor。如果我在 Gradle 4.8 中使用compileOnly 选项会怎样?

spring-boot

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

通过 Gradle 的 Spring Boot 自定义启动器

我在网上找到的任何教程都会通过 Maven 创建自定义 Spring Boot 启动器。有没有办法使用 Gradle 创建它?

我尝试使用gradle。它成功地为我创建了一个 jar 文件。条件是我必须有主课。我认为这是一个问题,因为我发现创建自定义启动器的任何在线教程中都没有主要方法。

第二个问题是它生成的 jar 文件(当像这样从 cmd 运行时工作得很好)java -jar jarname.jar具有一个目录结构,其中我的自定义配置不在根目录中。它的根部有与 Spring Boot 相关的东西。我确信我需要将我的类放在 jar 文件的根目录中。

因此我的问题是,如何通过 gradle 创建自定义启动项目?

java gradle spring-boot

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

如何获取不同时区的LocalTime?

我知道 LocalTime 与时区无关。但我想获得中部标准时间 (CST) 时区的时间。我得到的只是字符串中的时间:

String start = "11:00" //11 am CST. 
LocalTime startTime = LocalTime.parse(start);
Run Code Online (Sandbox Code Playgroud)

这很好,但服务器在不同的时区运行。因此它会将其解释为 UTC 时间上午 11 点。我希望当地时间为 CST。我需要在 CST 中。

java date

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

如何从JDBC中的SQL获取sequence.nextval?

我有 5 个表,我在其中使用相同序列的下一个值。问题是,后续表获得的值比以前的表大。

我的代码是这样的:

String sql = "INSERT INTO table1(id, name) VALUES (id_seq.nextval, ?)"; 
ps.setString(1, "bar"); 
ps.executeUpdate();     
sql = "INSERT INTO table2(id, name) VALUES (id_seq.nextval, ?)";
ps.setString(1, "tar"); 
ps.executeUpdate();
sql = "INSERT INTO table3(id, name) VALUES (id_seq.nextval, ?)";
ps.setString(1, "par"); 
ps.executeUpdate();
sql = "INSERT INTO table4(id, name) VALUES (id_seq.nextval, ?)";
ps.setString(1, "car"); 
ps.executeUpdate();
sql = "INSERT INTO table5(id, name) VALUES (id_seq.nextval, ?)";
ps.setString(1, "rar"); 
ps.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

我的顺序是这样的:

CREATE SEQUENCE  "ID_SEQ"  MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1         START WITH 10 CACHE …
Run Code Online (Sandbox Code Playgroud)

java mysql jdbc

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

multi_match 格式错误的查询,预期为 END_OBJECT,但找到了 FIELD_NAME

{
"from":0,
"size":1000,
   "query": {
      "bool": {
         "must": [
         {
               "query": {

"multi_match": {
     "query": "shampoo",
     "fields": ["summary.exact", "promotionid.basic"],
     "type": "cross_fields",
     "minimum_should_match" : "100%"
}
}
},
       {
        "bool": {
                    "should": [
                        {"term": {"is_non_ecomm": "1"}}                            
                    ],
                    "must": [
                       {"term": {
                          "iscouponactive": "1"
                       }}
                    ]
                }
                }
     ]

      }
   }
}
Run Code Online (Sandbox Code Playgroud)

我正在从 2x 迁移到 5x,但我的查询失败了。这是我得到的错误:

[multi_match] 格式错误的查询,预期 [END_OBJECT] 但发现 [FIELD_NAME]","line":32,"col":13}],"type":"parsing_exception","re​​ason":"[multi_match] 格式错误的查询,预期 [END_OBJECT] 但找到 [FIELD_NAME]","line":32,"col":13}

elasticsearch

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

迭代 Thymeleaf 中的地图列表

我有一个包含这样的地图的列表:

Map<String, Long> count = new HashMap<>();
count.put("totalMessageCount", 5L);         
Map<String, Map<String, Long>> names = new HashMap<>();
names.put("someKey", count);
List<Map<String, Map<String, Long>>> list = new ArrayList<>();
list.add(names);
Run Code Online (Sandbox Code Playgroud)

我将此列表从控制器发送到视图。

我已经尝试过这个:

<table>
        <tr th:each="element : ${list}">
        <td th:text="${element.key}"></td>
        <td th:text="${element.value}"></td>
</table>
Run Code Online (Sandbox Code Playgroud)

我收到错误:

org.springframework.expression.spel.SpelEvaluationException:EL1008E:在“java.util.HashMap”类型的对象上找不到属性或字段“key” - 可能不是公共的或无效?在 org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217) 在 org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) 在 org.springframework.expression.spel .ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51) 在...

任何帮助表示赞赏。

java thymeleaf spring-boot

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