小编Ald*_*lva的帖子

从 SpringBootTest 中排除 Configuration 类

我有一个类在 src/main/java 下配置 Kafka:

@Configuration
public class SenderConfig {

    @Value("${spring.kafka.producer.bootstrap-servers}")
    private String bootstrapServers;


    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Bean
    public ProducerFactory<String,Item> producerFactory(){
        log.info("Generating configuration to Kafka key and value");
        Map<String,Object> config = new HashMap<>();
        config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,bootstrapServers);
        config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
        return new DefaultKafkaProducerFactory(config);
    }
Run Code Online (Sandbox Code Playgroud)

我在 src/test/java 下有一个类来测试存储库,我想排除此配置类:

@SpringBootTest(properties = { "spring.cloud.config.enabled=false",
        "spring.autoconfigure.exclude=com.xyz.xyz.config.SenderConfig" })
@Sql({ "/import_cpo_workflow.sql" })
public class WorkflowServiceTest {

    @Autowired
    private WorkflowRep workflowRep;

    @Test
    public void testLoadDataForTestClass() {
        assertEquals(1, workflowRep.findAll().size());
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:由以下原因引起:java.lang.IllegalStateException:无法排除以下类,因为它们不是自动配置类:com.xyz.xyz.config.SenderConfig

既然我现在没有测试 Kafka,如何从我的测试中排除这个配置类?

spring spring-boot-test

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

Spring Cloud 配置服务器 - Git - 未授权

我有一个使用 Spring Cloud Config 的 Spring-Boot 应用程序,我正在尝试从 Bitbucket 获取应用程序的配置文件。我不久前能够获取配置文件,但现在当我尝试通过配置服务器 url 访问时出现错误。

应用程序.yml:

server:
    port: 8888
spring:
    application:
        name: config-server
    cloud:
        config:
            server:
                git:
                    password: ##########
                    username: ##########
                    uri: https://USERNAME@bitbucket.org/repositorios-closeup/cup-configuration-files
                    searchPaths: '{application}'
Run Code Online (Sandbox Code Playgroud)

当我尝试访问该 url 时,应用程序显示错误 -未授权

org.eclipse.jgit.api.errors.TransportException: https://USERNAME@bitbucket.org/repositorios-closeup/cup-configuration-files: not authorized

    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]

Run Code Online (Sandbox Code Playgroud)

有人知道发生了什么事吗?我已经检查了 bitbucket 上的所有凭据和 url。

bitbucket spring-boot spring-cloud-config

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

MVN 构建镜像 - “拨号 tcp:查找 github.com:名称解析暂时失败”

我正在尝试使用命令构建 docker 映像mvn spring-boot:build-image -P<environment>,但出现错误:

[INFO]     [creator]     Paketo BellSoft Liberica Buildpack 8.1.2
[INFO]     [creator]       https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_JVM_VERSION              8.*             the Java version
[INFO]     [creator]       Launch Configuration:
[INFO]     [creator]         $BPL_JVM_HEAD_ROOM           0               the headroom in memory calculation
[INFO]     [creator]         $BPL_JVM_LOADED_CLASS_COUNT  35% of classes  the number of loaded classes in memory calculation
[INFO]     [creator]         $BPL_JVM_THREAD_COUNT        250             the number of threads in memory calculation
[INFO]     [creator]         $JAVA_TOOL_OPTIONS                           the JVM launch flags
[INFO]     [creator]       BellSoft Liberica JRE 8.0.292: Contributing …
Run Code Online (Sandbox Code Playgroud)

maven spring-boot-maven-plugin docker-image

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

Java中的字符串'Y'为真,'N'为假

Java中是否有任何库可以将字符串“Y”转换为true或将“N”转换为false?

我做了一个枚举,但我不知道这是否是最好的方法:

public enum BooleanEnum {

    TRUE("Y"), FALSE("F");

    private String booleanValue;

    private BooleanEnum(String booleanValue) {
        this.booleanValue = booleanValue;
    }

    public String getBooleanValue() {
        return booleanValue;
    }

}
Run Code Online (Sandbox Code Playgroud)

并使用:

if (BooleanEnum.TRUE.getBooleanValue().equals(cpoPipelineDTO.getCpoPipelineCategory().getIsDataFlow())) {
Run Code Online (Sandbox Code Playgroud)

java java-8

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