BAEL-20882 Move Spring Boot Properties module to Spring Boot modules

This commit is contained in:
mikr 2020-01-26 23:58:19 +01:00
parent dd370f90bb
commit 31e161ce81
94 changed files with 174 additions and 175 deletions

View File

@ -667,7 +667,6 @@
<module>spring-boot-nashorn</module> <module>spring-boot-nashorn</module>
<module>spring-boot-parent</module> <module>spring-boot-parent</module>
<module>spring-boot-performance</module> <module>spring-boot-performance</module>
<module>spring-boot-properties</module>
<module>spring-boot-property-exp</module> <module>spring-boot-property-exp</module>
<module>spring-boot-rest</module> <module>spring-boot-rest</module>
@ -1206,7 +1205,6 @@
<module>spring-boot-nashorn</module> <module>spring-boot-nashorn</module>
<module>spring-boot-parent</module> <module>spring-boot-parent</module>
<module>spring-boot-performance</module> <module>spring-boot-performance</module>
<module>spring-boot-properties</module>
<module>spring-boot-property-exp</module> <module>spring-boot-property-exp</module>
<module>spring-boot-rest</module> <module>spring-boot-rest</module>

View File

@ -15,6 +15,7 @@
<modules> <modules>
<module>spring-boot-mvc-birt</module> <module>spring-boot-mvc-birt</module>
<module>spring-boot-properties</module>
<module>spring-boot-vue</module> <module>spring-boot-vue</module>
</modules> </modules>

View File

@ -11,7 +11,7 @@
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath> <relativePath>../../parent-boot-2</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -1,75 +1,75 @@
package com.baeldung.valuewithdefaults; package com.baeldung.valuewithdefaults;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
/** /**
* Demonstrates setting defaults for @Value annotation. Note that there are no properties * Demonstrates setting defaults for @Value annotation. Note that there are no properties
* defined in the specified property source. We also assume that the user here * defined in the specified property source. We also assume that the user here
* does not have a system property named some.key. * does not have a system property named some.key.
* *
*/ */
@Configuration @Configuration
@PropertySource(name = "myProperties", value = "valueswithdefaults.properties") @PropertySource(name = "myProperties", value = "valueswithdefaults.properties")
public class ValuesWithDefaultsApp { public class ValuesWithDefaultsApp {
@Value("${some.key:my default value}") @Value("${some.key:my default value}")
private String stringWithDefaultValue; private String stringWithDefaultValue;
@Value("${some.key:}") @Value("${some.key:}")
private String stringWithBlankDefaultValue; private String stringWithBlankDefaultValue;
@Value("${some.key:true}") @Value("${some.key:true}")
private boolean booleanWithDefaultValue; private boolean booleanWithDefaultValue;
@Value("${some.key:42}") @Value("${some.key:42}")
private int intWithDefaultValue; private int intWithDefaultValue;
@Value("${some.key:one,two,three}") @Value("${some.key:one,two,three}")
private String[] stringArrayWithDefaults; private String[] stringArrayWithDefaults;
@Value("${some.key:1,2,3}") @Value("${some.key:1,2,3}")
private int[] intArrayWithDefaults; private int[] intArrayWithDefaults;
@Value("#{systemProperties['some.key'] ?: 'my default system property value'}") @Value("#{systemProperties['some.key'] ?: 'my default system property value'}")
private String spelWithDefaultValue; private String spelWithDefaultValue;
public static void main(String[] args) { public static void main(String[] args) {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class); ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class);
} }
@PostConstruct @PostConstruct
public void afterInitialize() { public void afterInitialize() {
// strings // strings
Assert.isTrue(stringWithDefaultValue.equals("my default value")); Assert.isTrue(stringWithDefaultValue.equals("my default value"));
Assert.isTrue(stringWithBlankDefaultValue.equals("")); Assert.isTrue(stringWithBlankDefaultValue.equals(""));
// other primitives // other primitives
Assert.isTrue(booleanWithDefaultValue); Assert.isTrue(booleanWithDefaultValue);
Assert.isTrue(intWithDefaultValue == 42); Assert.isTrue(intWithDefaultValue == 42);
// arrays // arrays
List<String> stringListValues = Lists.newArrayList("one", "two", "three"); List<String> stringListValues = Lists.newArrayList("one", "two", "three");
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues)); Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
List<Integer> intListValues = Lists.newArrayList(1, 2, 3); List<Integer> intListValues = Lists.newArrayList(1, 2, 3);
Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues)); Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues));
// SpEL // SpEL
Assert.isTrue(spelWithDefaultValue.equals("my default system property value")); Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
} }
} }

View File

@ -1,31 +1,31 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package com.baeldung.yaml; package com.baeldung.yaml;
import java.util.Collections; import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class MyApplication implements CommandLineRunner { public class MyApplication implements CommandLineRunner {
@Autowired @Autowired
private YAMLConfig myConfig; private YAMLConfig myConfig;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication app = new SpringApplication(MyApplication.class); SpringApplication app = new SpringApplication(MyApplication.class);
app.run(); app.run();
} }
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
System.out.println("using environment:" + myConfig.getEnvironment()); System.out.println("using environment:" + myConfig.getEnvironment());
System.out.println("name:" + myConfig.getName()); System.out.println("name:" + myConfig.getName());
System.out.println("servers:" + myConfig.getServers()); System.out.println("servers:" + myConfig.getServers());
} }
} }

View File

@ -1,41 +1,41 @@
package com.baeldung.yaml; package com.baeldung.yaml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConfigurationProperties @ConfigurationProperties
public class YAMLConfig { public class YAMLConfig {
private String name; private String name;
private String environment; private String environment;
private List<String> servers = new ArrayList<String>(); private List<String> servers = new ArrayList<String>();
public List<String> getServers() { public List<String> getServers() {
return servers; return servers;
} }
public void setServers(List<String> servers) { public void setServers(List<String> servers) {
this.servers = servers; this.servers = servers;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getEnvironment() { public String getEnvironment() {
return environment; return environment;
} }
public void setEnvironment(String environment) { public void setEnvironment(String environment) {
this.environment = environment; this.environment = environment;
} }
} }

View File

@ -1,25 +1,25 @@
package com.baeldung.test; package com.baeldung.test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import com.baeldung.properties.basic.ExtendedPropertiesWithJavaIntegrationTest; import com.baeldung.properties.basic.ExtendedPropertiesWithJavaIntegrationTest;
import com.baeldung.properties.basic.PropertiesWithMultipleXmlsIntegrationTest; import com.baeldung.properties.basic.PropertiesWithMultipleXmlsIntegrationTest;
import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest; import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest;
import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest;
import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest; import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest;
import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest; import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ //@formatter:off @SuiteClasses({ //@formatter:off
PropertiesWithXmlIntegrationTest.class, PropertiesWithXmlIntegrationTest.class,
ExternalPropertiesWithJavaIntegrationTest.class, ExternalPropertiesWithJavaIntegrationTest.class,
ExternalPropertiesWithMultipleXmlsIntegrationTest.class, ExternalPropertiesWithMultipleXmlsIntegrationTest.class,
ExternalPropertiesWithXmlManualTest.class, ExternalPropertiesWithXmlManualTest.class,
ExtendedPropertiesWithJavaIntegrationTest.class, ExtendedPropertiesWithJavaIntegrationTest.class,
PropertiesWithMultipleXmlsIntegrationTest.class, PropertiesWithMultipleXmlsIntegrationTest.class,
})// @formatter:on })// @formatter:on
public final class IntegrationTestSuite { public final class IntegrationTestSuite {
// //
} }