BAEL-20882 Move Spring Boot Properties module to Spring Boot modules
This commit is contained in:
parent
dd370f90bb
commit
31e161ce81
2
pom.xml
2
pom.xml
|
@ -667,7 +667,6 @@
|
|||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-parent</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>spring-boot-property-exp</module>
|
||||
|
||||
<module>spring-boot-rest</module>
|
||||
|
@ -1206,7 +1205,6 @@
|
|||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-parent</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>spring-boot-property-exp</module>
|
||||
|
||||
<module>spring-boot-rest</module>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
<modules>
|
||||
<module>spring-boot-mvc-birt</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>spring-boot-vue</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
|
@ -1,75 +1,75 @@
|
|||
package com.baeldung.valuewithdefaults;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* does not have a system property named some.key.
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@PropertySource(name = "myProperties", value = "valueswithdefaults.properties")
|
||||
public class ValuesWithDefaultsApp {
|
||||
|
||||
@Value("${some.key:my default value}")
|
||||
private String stringWithDefaultValue;
|
||||
|
||||
@Value("${some.key:}")
|
||||
private String stringWithBlankDefaultValue;
|
||||
|
||||
@Value("${some.key:true}")
|
||||
private boolean booleanWithDefaultValue;
|
||||
|
||||
@Value("${some.key:42}")
|
||||
private int intWithDefaultValue;
|
||||
|
||||
@Value("${some.key:one,two,three}")
|
||||
private String[] stringArrayWithDefaults;
|
||||
|
||||
@Value("${some.key:1,2,3}")
|
||||
private int[] intArrayWithDefaults;
|
||||
|
||||
@Value("#{systemProperties['some.key'] ?: 'my default system property value'}")
|
||||
private String spelWithDefaultValue;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void afterInitialize() {
|
||||
// strings
|
||||
Assert.isTrue(stringWithDefaultValue.equals("my default value"));
|
||||
Assert.isTrue(stringWithBlankDefaultValue.equals(""));
|
||||
|
||||
// other primitives
|
||||
Assert.isTrue(booleanWithDefaultValue);
|
||||
Assert.isTrue(intWithDefaultValue == 42);
|
||||
|
||||
// arrays
|
||||
List<String> stringListValues = Lists.newArrayList("one", "two", "three");
|
||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
|
||||
|
||||
List<Integer> intListValues = Lists.newArrayList(1, 2, 3);
|
||||
Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues));
|
||||
|
||||
// SpEL
|
||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
|
||||
|
||||
}
|
||||
}
|
||||
package com.baeldung.valuewithdefaults;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* does not have a system property named some.key.
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@PropertySource(name = "myProperties", value = "valueswithdefaults.properties")
|
||||
public class ValuesWithDefaultsApp {
|
||||
|
||||
@Value("${some.key:my default value}")
|
||||
private String stringWithDefaultValue;
|
||||
|
||||
@Value("${some.key:}")
|
||||
private String stringWithBlankDefaultValue;
|
||||
|
||||
@Value("${some.key:true}")
|
||||
private boolean booleanWithDefaultValue;
|
||||
|
||||
@Value("${some.key:42}")
|
||||
private int intWithDefaultValue;
|
||||
|
||||
@Value("${some.key:one,two,three}")
|
||||
private String[] stringArrayWithDefaults;
|
||||
|
||||
@Value("${some.key:1,2,3}")
|
||||
private int[] intArrayWithDefaults;
|
||||
|
||||
@Value("#{systemProperties['some.key'] ?: 'my default system property value'}")
|
||||
private String spelWithDefaultValue;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void afterInitialize() {
|
||||
// strings
|
||||
Assert.isTrue(stringWithDefaultValue.equals("my default value"));
|
||||
Assert.isTrue(stringWithBlankDefaultValue.equals(""));
|
||||
|
||||
// other primitives
|
||||
Assert.isTrue(booleanWithDefaultValue);
|
||||
Assert.isTrue(intWithDefaultValue == 42);
|
||||
|
||||
// arrays
|
||||
List<String> stringListValues = Lists.newArrayList("one", "two", "three");
|
||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
|
||||
|
||||
List<Integer> intListValues = Lists.newArrayList(1, 2, 3);
|
||||
Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues));
|
||||
|
||||
// SpEL
|
||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.yaml;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MyApplication implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private YAMLConfig myConfig;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(MyApplication.class);
|
||||
app.run();
|
||||
}
|
||||
|
||||
public void run(String... args) throws Exception {
|
||||
System.out.println("using environment:" + myConfig.getEnvironment());
|
||||
System.out.println("name:" + myConfig.getName());
|
||||
System.out.println("servers:" + myConfig.getServers());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.yaml;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MyApplication implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private YAMLConfig myConfig;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(MyApplication.class);
|
||||
app.run();
|
||||
}
|
||||
|
||||
public void run(String... args) throws Exception {
|
||||
System.out.println("using environment:" + myConfig.getEnvironment());
|
||||
System.out.println("name:" + myConfig.getName());
|
||||
System.out.println("servers:" + myConfig.getServers());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +1,41 @@
|
|||
package com.baeldung.yaml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@ConfigurationProperties
|
||||
public class YAMLConfig {
|
||||
private String name;
|
||||
private String environment;
|
||||
private List<String> servers = new ArrayList<String>();
|
||||
|
||||
public List<String> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public void setServers(List<String> servers) {
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(String environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
}
|
||||
package com.baeldung.yaml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@ConfigurationProperties
|
||||
public class YAMLConfig {
|
||||
private String name;
|
||||
private String environment;
|
||||
private List<String> servers = new ArrayList<String>();
|
||||
|
||||
public List<String> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public void setServers(List<String> servers) {
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(String environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +1,25 @@
|
|||
package com.baeldung.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import com.baeldung.properties.basic.ExtendedPropertiesWithJavaIntegrationTest;
|
||||
import com.baeldung.properties.basic.PropertiesWithMultipleXmlsIntegrationTest;
|
||||
import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ //@formatter:off
|
||||
PropertiesWithXmlIntegrationTest.class,
|
||||
ExternalPropertiesWithJavaIntegrationTest.class,
|
||||
ExternalPropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
ExternalPropertiesWithXmlManualTest.class,
|
||||
ExtendedPropertiesWithJavaIntegrationTest.class,
|
||||
PropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
})// @formatter:on
|
||||
public final class IntegrationTestSuite {
|
||||
//
|
||||
}
|
||||
package com.baeldung.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import com.baeldung.properties.basic.ExtendedPropertiesWithJavaIntegrationTest;
|
||||
import com.baeldung.properties.basic.PropertiesWithMultipleXmlsIntegrationTest;
|
||||
import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ //@formatter:off
|
||||
PropertiesWithXmlIntegrationTest.class,
|
||||
ExternalPropertiesWithJavaIntegrationTest.class,
|
||||
ExternalPropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
ExternalPropertiesWithXmlManualTest.class,
|
||||
ExtendedPropertiesWithJavaIntegrationTest.class,
|
||||
PropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
})// @formatter:on
|
||||
public final class IntegrationTestSuite {
|
||||
//
|
||||
}
|
Loading…
Reference in New Issue