@Bean @ConditionalOnEnabledInfoContributor("build") @ConditionalOnSingleCandidate(BuildProperties.class) @Order(DEFAULT_ORDER) public InfoContributor buildInfoContributor(BuildProperties buildProperties) { return new BuildInfoContributor(buildProperties); }
@Bean public BuildProperties buildProperties() { Properties properties = new Properties(); properties.put("group", "com.example"); properties.put("artifact", "demo"); properties.put("foo", "bar"); return new BuildProperties(properties); }
@ConditionalOnResource(resources = "${spring.info.build.location:classpath:META-INF/build-info.properties}") @ConditionalOnMissingBean @Bean public BuildProperties buildProperties() throws Exception { return new BuildProperties( loadFrom(this.properties.getBuild().getLocation(), "build")); }
@Test public void buildPropertiesDefaultLocation() { load(); BuildProperties buildProperties = this.context.getBean(BuildProperties.class); assertThat(buildProperties.getGroup()).isEqualTo("com.example"); assertThat(buildProperties.getArtifact()).isEqualTo("demo"); assertThat(buildProperties.getName()).isEqualTo("Demo Project"); assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT"); assertThat(buildProperties.getTime().getTime()).isEqualTo(1457100965000L); }
@Test public void buildPropertiesCustomLocation() { load("spring.info.build.location=classpath:/org/springframework/boot/autoconfigure/info/build-info.properties"); BuildProperties buildProperties = this.context.getBean(BuildProperties.class); assertThat(buildProperties.getGroup()).isEqualTo("com.example.acme"); assertThat(buildProperties.getArtifact()).isEqualTo("acme"); assertThat(buildProperties.getName()).isEqualTo("acme"); assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT"); assertThat(buildProperties.getTime().getTime()).isEqualTo(1457088120000L); }
@Test public void buildPropertiesCustomInvalidLocation() { load("spring.info.build.location=classpath:/org/acme/no-build-info.properties"); Map<String, BuildProperties> beans = this.context .getBeansOfType(BuildProperties.class); assertThat(beans).hasSize(0); }
@Test public void buildPropertiesFallbackWithBuildInfoBean() { load(CustomInfoPropertiesConfiguration.class); BuildProperties buildProperties = this.context.getBean(BuildProperties.class); assertThat(buildProperties) .isSameAs(this.context.getBean("customBuildProperties")); }
@Autowired public Info(PermissionService permissionService, BuildProperties buildProperties, RestTemplate restTemplate) { this.permissionService = permissionService; this.buildProperties = buildProperties; this.restTemplate = restTemplate; }
public BuildInfoContributor(BuildProperties properties) { super(properties, Mode.FULL); }
@Bean public BuildInfoContributor customBuildInfoContributor() { return new BuildInfoContributor(new BuildProperties(new Properties())); }
@Bean public BuildProperties customBuildProperties() { return new BuildProperties(new Properties()); }
public BuildInfo fromProperties(BuildProperties properties) { return new BuildInfo(properties.getVersion(), properties.getTime()); }