小编All*_*afe的帖子

Jest 错误无法定位模块 .... 映射为:

我尝试使用JestVueJSQuasar framework。我写了一个简单的测试:

import { GetUserDictionaryDataComponent, Component } from '@/pages/configurations/components/';

describe('GetUserDictionaryDataComponent', () => {
  it('should get correct type', () => {
    const component = new GetUserDictionaryDataComponent(undefined);
    expect(component.getComponentType()).toBe(Component.LEAF);
  });
});
Run Code Online (Sandbox Code Playgroud)

但它不能正常工作。当我尝试运行我的测试时,出现错误:

Test suite failed to run

    Configuration error:

    Could not locate module @/pages/configurations/components/ mapped as:
    /home/user/git/my_project/client/src/pages/configurations/components/.

    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^@\/(.*)$/": "/home/user/git/my_project/client/src/$1"
      },
      "resolver": null
    }

    > 1 | import { GetUserDictionaryDataComponent, Component } from '@/pages/configurations/components/';
        | ^
      2 | …
Run Code Online (Sandbox Code Playgroud)

vue.js jestjs quasar-framework

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

使用 Spring Boot Actuator 记录所有请求和响应

我正在使用 Spring Boot 和 REST 服务,使用@RestController. 我想用有效负载记录所有请求和响应。我该如何使用 来做到这一点Spring Boot Actuator?当我使用:

    @Bean
    public ServletContextRequestLoggingFilter requestLoggingFilter() {
        ServletContextRequestLoggingFilter loggingFilter = new ServletContextRequestLoggingFilter();
        loggingFilter.setIncludeClientInfo(true);
        loggingFilter.setIncludeQueryString(true);
        loggingFilter.setIncludePayload(true);
        loggingFilter.setIncludeHeaders(true);
        loggingFilter.setMaxPayloadLength(10000);
        loggingFilter.setAfterMessagePrefix("REQUEST DATA : ");
        return loggingFilter;
    }
Run Code Online (Sandbox Code Playgroud)

我只收到请求,但没有收到响应。

java spring-mvc spring-boot

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

使用 TestContainers 和 Jenkins 在 docker 容器中运行测试(docker.sock 权限被拒绝)

在我的测试中,我使用TestContainers. 我想使用 Jenkins 在容器中运行测试。我为运行测试创建了这个图像maven。Dockerfile:

FROM registry.company.com/maven:3-jdk-8-slim

RUN apt update
RUN apt install -y wget libatomic1 curl gnupg

RUN wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/ndbclient_7.6.10-1debian9_amd64.deb \
&& dpkg -i ndbclient_7.6.10-1debian9_amd64.deb && rm ndbclient_7.6.10-1debian9_amd64.deb
RUN ln -s /usr/lib/x86_64-linux-gnu/libndbclient.so.6.1.0 /usr/lib/x86_64-linux-gnu/libndbclient.so

RUN curl -sL https://deb.nodesource.com/setup_10.x  | bash -
RUN apt-get -y install nodejs

RUN groupadd --gid 10000 ldap && useradd -m --uid 10028 --gid 10000 jenkins
RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers

COPY settings.xml /home/jenkins/

USER jenkins
Run Code Online (Sandbox Code Playgroud)

在我的测试中,我使用MySQL Cluster容器。

对于Jenkins …

java jenkins docker testcontainers

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

在多模块项目中使用 Liquibase

我有两个模块(editorengine)与一个公共数据库一起工作。对于我想使用的脚本的部署liquibase。我不想在两个地方复制相同的脚本,我想在一个地方管理它们。为此,我创建了一个单独的模块 ( database-structure),其中仅包含我的脚本和参数spring .liquibase.change-log=classpath:db/changelog/db.changelog-master.xml。我已将此模块 ( database-structure)添加为其他模块的依赖项。最终结构如下(为了紧凑,省略了类):

D:\PROJECTS\MY-PROJECT
????database-structure
?   ?   pom.xml
?   ?
?   ????src
?       ????main
?       ?   ????java
?       ?   ????resources
?       ?       ?   application.properties
?       ?       ?
?       ?       ????db
?       ?           ????changelog
?       ?               ?   db.changelog-master.xml
?       ?               ?
?       ?               ????1.0
?       ?                       db.changelog-1.0.xml
?       ?                       metadata_create.sql
?       ?                       metadata_insert_data.sql
?       ?                       metadata_rollback.sql
?       ?
?       ????test
?           ????java
????editor
?   ?   pom.xml
?   ? …
Run Code Online (Sandbox Code Playgroud)

java liquibase multi-module spring-boot

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

Avro 与 Java BigDecimal 类型

我尝试使用以下类型创建Avro架构BigDecimal

SchemaBuilder.FieldAssembler<Schema> schemaFieldAssembler = SchemaBuilder.record("AvroEventRequest2")
                .namespace("com.test")
                .fields();
for (Map.Entry<String, Object> entry : inputData.entrySet()) {
    if (entry.getValue() instanceof String) {
            //some operations
    } else if (entry.getValue() instanceof BigDecimal) {
        Schema decimalSchema = LogicalTypes.decimal(4)
                        .addToSchema(Schema.create(Schema.Type.BYTES));
        schemaFieldAssembler = schemaFieldAssembler.name(entry.getKey())
                        .type(decimalSchema).noDefault();
   }
}
Run Code Online (Sandbox Code Playgroud)

我读了这个文档: https: //avro.apache.org/docs/1.8.1/spec.html#Decimal,但它对我不起作用。我得到异常:

Caused by: org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBuffer
    at org.apache.avro.generic.GenericDatumWriter.writeBytes(GenericDatumWriter.java:260) ~[avro-1.8.1.jar:1.8.1]
    at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:116) ~[avro-1.8.1.jar:1.8.1]
    at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:70) ~[avro-1.8.1.jar:1.8.1]
Run Code Online (Sandbox Code Playgroud)

如何序列化 BigDecimal 类型?

java avro

5
推荐指数
0
解决办法
3838
查看次数

从一个非常大的表中获取数据

我在 MySQL 数据库中有一个非常大的表,表中有 2 亿条记录Users

我使用 JDBC 进行查询:

public List<Pair<Long, String>> getUsersAll() throws SQLException {
        Connection cnn = null;
        CallableStatement cs = null;
        ResultSet rs = null;
        final List<Pair<Long, String>> res = new ArrayList<>();
        try {
            cnn = dataSource.getConnection();
            cs = cnn.prepareCall("select UserPropertyKindId, login from TEST.users;");
            rs = cs.executeQuery();
            while (rs.next()) {
                res.add(new ImmutablePair<>(rs.getLong(1), rs.getString(2)));
            }
            return res;
        } catch (SQLException ex) {
            throw ex;
        } finally {
            DbUtils.closeQuietly(cnn, cs, rs);
        }
    }
Run Code Online (Sandbox Code Playgroud)

接下来,我处理结果:

List<Pair<Long, String>> users= dao.getUsersAll(); …
Run Code Online (Sandbox Code Playgroud)

java mysql multithreading jdbc producer-consumer

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

使用 karma 在无头模式下启动 Firefox

我使用Angular和'业力'。我的 conf 看起来像这样:

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular-devkit/build-angular'],
        plugins: [
            require('karma-jasmine'),
            require('karma-jasmine-html-reporter'),
            require('karma-coverage-istanbul-reporter'),
            require('@angular-devkit/build-angular/plugins/karma'),
            require('karma-firefox-launcher')
        ],
        client: {
            clearContext: false // leave Jasmine Spec Runner output visible in browser
        },
        coverageIstanbulReporter: {
            dir: require('path').join(__dirname, '../coverage'),
            reports: ['html', 'lcovonly'],
            fixWebpackSourcePaths: true
        },
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['FirefoxHeadless'],
        customLaunchers: {
            'FirefoxHeadless': {
                base: 'Firefox',
                flags: [
                    '-headless',
                ],
            }
        },
        singleRun: true
    });
};
Run Code Online (Sandbox Code Playgroud)

但是,当我发出命令时:

ng …
Run Code Online (Sandbox Code Playgroud)

firefox karma-runner karma-jasmine angular

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

使用 jackson-dataformat-csv 获取 csv 的标题

我使用jackson-dataformat-csv图书馆。我要解析CSV文件。我有这个代码:

 CsvMapper csvMapper = new CsvMapper();
        CsvSchema csvSchema = csvMapper.typedSchemaFor(Map.class).withHeader();
        List<Map<String, String>> csvRows;
        try {
            MappingIterator<Map<String, String>> it = csvMapper.readerFor(Map.class)
                    .with(csvSchema.withColumnSeparator(';'))
                    .readValues(file.getInputStream());
            csvRows = it.readAll();
        } catch (Exception ex) {
            log.error("Unable to read csv document: ", ex);
        }
Run Code Online (Sandbox Code Playgroud)

我想从这个文件中获取列名。但我不明白如何制作。我尝试:

csvSchema._columns
Run Code Online (Sandbox Code Playgroud)

但是,它是空对象。我也是这样做的:

csvSchema.column(0)
Run Code Online (Sandbox Code Playgroud)

我得到错误:

Method threw 'java.lang.ArrayIndexOutOfBoundsException' exception.
Run Code Online (Sandbox Code Playgroud)

显然,列对象是空的。为什么?我如何从中获取列名数组CSV

java csv jackson

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

从流中获取父对象

我有这门课:

public class StructUserType extends UserType {

    MembersList membersList = new MembersList();

    public List<Member> getMembers() {
        return Collections.unmodifiableList(membersList.members);
    }

    static class MembersList {
        List<Member> members = new ArrayList<>();
    }

    public static class Member implements Identifiable {
        private Integer id;

        public Integer getId() {
            return id;
        }
    }    
} 
Run Code Online (Sandbox Code Playgroud)

我有一个List对象:

List<SmbpUserType> userTypes = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

我想找到Member哪个等于某个id.我尝试如下:

Integer id = 1;
userTypes.stream()
                .filter(StructUserType.class::isInstance)
                .map(StructUserType.class::cast)
                .forEach(structUserType -> {
                    structUserType.getMembers()
                            .stream()
                            .filter(m -> m.getId() == id)
                            .findFirst().orElse(null);
                });
Run Code Online (Sandbox Code Playgroud)

我想,当内部流中的过滤器运行并找到第一个成员时,返回该成员包含的父元素,即那些UserType …

java java-8 java-stream

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

Spring Boot 2.0.4 中从 http 重定向到 https

我用Spring boot 2.0.4。我想为所有 url 模式配置从 http 到 https 的自动重定向。我在 application.yml 中添加以下几行:

server:
  ssl:
    enabled: true
    key-alias: tomcat
    key-store: "classpath:tomcat.keystore"
    key-store-type: jks
    key-store-password: 123456
    key-password: 123456
Run Code Online (Sandbox Code Playgroud)

我创建了 bean:

    @Bean
    public TomcatServletWebServerFactory httpsRedirectConfig() {
        return new TomcatServletWebServerFactory () {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
    }
Run Code Online (Sandbox Code Playgroud)

但是,当我运行我的应用程序时,出现错误:

Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans : tomcatServletWebServerFactory,httpsRedirectConfig
Run Code Online (Sandbox Code Playgroud)

怎么了?我该如何修复它?谢谢。

java https spring spring-boot

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