These are chat archives for spring-cloud/spring-cloud

3rd
Apr 2018
Vishnu4a7
@Vishnu4a7
Apr 03 2018 13:43
Is there any solution to convert date from yyyy-mmm-dd to epoch_millis format in shell script?
Gigen Thomas
@gigenthomas
Apr 03 2018 15:26
Recently upgraded from Spring boot 1.5 to 2.0. Spring-cloud-vault no longer recognizes the vault configuration. Here's the entry in build.gradle - compile 'org.springframework.cloud:spring-cloud-starter-vault-config'. What am I missing ?
玹霖
@SoftwareKing
Apr 03 2018 16:24
@ryanjbaxter spring-cloud/spring-cloud-openfeign#14
@spencergibb spring-cloud/spring-cloud-openfeign#14
Florian Lautenschlager
@FlorianLautenschlager
Apr 03 2018 17:28
Hi there, i wonder if there is an easy way to check if a cache hits. Given: i have a method with two annotations: @Cacheable and a custom one @TraceDatabaseCall. The second one measures the execution time. But i only want to measure the time if the database call was not cached. :-)
Spencer Gibb
@spencergibb
Apr 03 2018 17:33
@FlorianLautenschlager not a spring cloud question
Ashok Koyi
@thekalinga
Apr 03 2018 21:06

I have configuration class like this.

@RefreshScope
@Configuration
public class DatabaseConfiguration {

    @Bean
  @Primary
  @RefreshScope
  @Conditional(MockRepositoryEnabledCondition.class)
  TodoRepository mockRepository() {
    return MockTodoRepository();
  }

}

class MockRepositoryEnabledCondition extends SpringBootCondition {

  @Override
  public ConditionOutcome getMatchOutcome(ConditionContext context,
      AnnotatedTypeMetadata metadata) {
    String useMockRepo = context.getEnvironment().getProperty("use.mock.repo");
    return useMockRepo != null && "true".equalsIgnoreCase(useMockRepo) ?
        match("Mock is enabled") :
        noMatch("Mock is not enabled");
  }

}

When I try to set the property use.mock.repo in the env at runtime & try to refresh the application context using /actuator/refresh, the custom condition is not getting evaluated. Any idea why this might be the case

This condition is only evaluated at the start of the application. Because of this, I'm not able to activate different set of beans at runtime
Ashok Koyi
@thekalinga
Apr 03 2018 21:41

I have created a simple application to demonstrate the issue

Here is the complete class, configuration & the commands I executed to test the flow


@RestController("/")
@SpringBootApplication
public class Log4j2TestApplication {

  private final Supplier<String> supplier;

  public static void main(String[] args) {
    SpringApplication.run(Log4j2TestApplication.class, args);
  }

  public Log4j2TestApplication(Supplier<String> supplier) {
    this.supplier = supplier;
  }

  @GetMapping("/")
  public String get() {
    return supplier.get();
  }

}

@Configuration
class MockConfiguration {

  @Bean
  @RefreshScope
  @Conditional(MockCondition.class)
  Supplier<String> mock() {
    return () -> "Using Mock";
  }

  @Bean
  @RefreshScope
  @Conditional(NotMockCondition.class)
  Supplier<String> notMock() {
    return () -> "Not Using Mock";
  }

}

class MockCondition extends SpringBootCondition {

  @Override
  public ConditionOutcome getMatchOutcome(ConditionContext context,
      AnnotatedTypeMetadata metadata) {
    String useMockRepo = context.getEnvironment().getProperty("mock");
    return useMockRepo != null && "true".equalsIgnoreCase(useMockRepo) ?
        match("Mock is enabled") :
        noMatch("Mock is not enabled");
  }

}

class NotMockCondition extends SpringBootCondition {

  @Override
  public ConditionOutcome getMatchOutcome(ConditionContext context,
      AnnotatedTypeMetadata metadata) {
    String useMockRepo = context.getEnvironment().getProperty("mock");
    return useMockRepo == null || !"true".equalsIgnoreCase(useMockRepo) ?
        match("Mock is not enabled") :
        noMatch("Mock is enabled");
  }

}

application.yml

spring:
  application:
    name: log4j2-test
management:
  endpoint:
    env:
      post:
        enabled: true
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include:
          - '*'

build.gradle

buildscript {
  ext {
    springBootVersion = '2.0.0.RELEASE'
  }
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
  }
}

ext {
  springCloudVersion='Finchley.M8'
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
  mavenCentral()
  maven { url "https://repo.spring.io/milestone" }
}

dependencies {
  compile('org.springframework.boot:spring-boot-starter-web')
  compile('org.springframework.boot:spring-boot-starter-actuator')
  compile('org.springframework.cloud:spring-cloud-starter-bus-amqp')
  compileOnly('org.projectlombok:lombok')
  testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
  imports {
    mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
  }
}

After starting the App, I ran the following commands (I used httpie for testing)

  1. http -b :8080/ returned Not Using Mock
  2. http -b :8080/actuator/env name=mock value=true to update the environment
  3. http -b :8080/actuator/env?pattern=mock to check that the environment is updated with mock proopery
  4. http -b POST :8080/actuator/refresh to refresh application context such that refresh scoped beans should have been refreshed
  5. http -b :8080/ => STILL RETURNS Not Using Mock
Any idea on why the refresh is not working?