JAVA-8356: split or move spring-boot-properties
This commit is contained in:
@@ -9,6 +9,5 @@ This module contains articles about Properties in Spring Boot.
|
||||
- [Properties with Spring and Spring Boot](https://www.baeldung.com/properties-with-spring) - checkout the `com.baeldung.properties` package for all scenarios of properties injection and usage
|
||||
- [Spring YAML Configuration](https://www.baeldung.com/spring-yaml)
|
||||
- [Add Build Properties to a Spring Boot Application](https://www.baeldung.com/spring-boot-build-properties)
|
||||
- [IntelliJ – Cannot Resolve Spring Boot Configuration Properties Error](https://www.baeldung.com/intellij-resolve-spring-boot-configuration-properties)
|
||||
- [Spring YAML vs Properties](https://www.baeldung.com/spring-yaml-vs-properties)
|
||||
- More articles: [[more -->]](../spring-boot-properties-2)
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.boot.context.properties.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "com.baeldung")
|
||||
public class CustomProperties {
|
||||
|
||||
/**
|
||||
* The url to connect to.
|
||||
*/
|
||||
String url;
|
||||
|
||||
/**
|
||||
* The time to wait for the connection.
|
||||
*/
|
||||
private int timeoutInMilliSeconds = 1000;
|
||||
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getTimeoutInMilliSeconds() {
|
||||
return timeoutInMilliSeconds;
|
||||
}
|
||||
|
||||
public void setTimeoutInMilliSeconds(int timeoutInMilliSeconds) {
|
||||
this.timeoutInMilliSeconds = timeoutInMilliSeconds;
|
||||
}
|
||||
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.boot.*;
|
||||
import org.springframework.boot.autoconfigure.*;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.boot.context.properties.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "com.baeldung")
|
||||
public class JdbcProperties {
|
||||
|
||||
@Value("${jdbc.url:jdbc:postgresql:/localhost:5432}")
|
||||
private String jdbcUrl;
|
||||
|
||||
public String getJdbcUrl() {
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
public void setJdbcUrl(String jdbcUrl) {
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
@Component
|
||||
public class PropertyBeanInjection {
|
||||
|
||||
private CustomProperties customProperties;
|
||||
|
||||
private JdbcProperties jdbcProperties;
|
||||
|
||||
PropertyBeanInjection(@Autowired CustomProperties customProperties, @Autowired JdbcProperties jdbcProperties) {
|
||||
this.customProperties = customProperties;
|
||||
this.jdbcProperties = jdbcProperties;
|
||||
}
|
||||
|
||||
String getUrl() {
|
||||
return customProperties.getUrl();
|
||||
}
|
||||
|
||||
String getJdbcUrl() {
|
||||
return jdbcProperties.getJdbcUrl();
|
||||
}
|
||||
|
||||
int getTimeoutInMilliseconds() {
|
||||
return customProperties.getTimeoutInMilliSeconds();
|
||||
}
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
com.baeldung.url=www.abc.test.com
|
||||
com.baeldung.jdbc.url=
|
||||
com.baeldung.timeout-in-milli-seconds=2000
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.runner.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.springframework.boot.test.context.*;
|
||||
import org.springframework.test.context.*;
|
||||
import org.springframework.test.context.junit4.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource("/configuration-processor.properties")
|
||||
@SpringBootTest(classes = DemoApplication.class)
|
||||
class PropertyBeanInjectionUnitTest {
|
||||
|
||||
@Autowired
|
||||
private PropertyBeanInjection propertyBeanInjection;
|
||||
|
||||
@Test
|
||||
void checkThatJdbcPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||
Assertions.assertEquals("jdbc:postgresql:/localhost:5432", propertyBeanInjection.getJdbcUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||
Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl());
|
||||
Assertions.assertEquals(2000, propertyBeanInjection.getTimeoutInMilliseconds());
|
||||
}
|
||||
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
com.baeldung.url=www.abc.test.com
|
||||
com.baeldung.jdbc.url=
|
||||
com.baeldung.timeout-in-milli-seconds=2000
|
||||
Reference in New Issue
Block a user