diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java
index e54f28837d..e280bbd79f 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java
+++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/ConfigPropertiesDemoApplication.java
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan;
import com.baeldung.configurationproperties.ConfigProperties;
@SpringBootApplication
-@ComponentScan(basePackageClasses = { ConfigProperties.class, JsonProperties.class, CustomJsonProperties.class, Database.class })
+@ComponentScan(basePackageClasses = { ConfigProperties.class, JsonProperties.class, CustomJsonProperties.class})
public class ConfigPropertiesDemoApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ConfigPropertiesDemoApplication.class).initializers(new JsonPropertyContextInitializer())
diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/Database.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/Database.java
deleted file mode 100644
index 6e798672e7..0000000000
--- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/Database.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.baeldung.properties;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@ConfigurationProperties(prefix = "database")
-public class Database {
-
- private String url;
- private String username;
- private String password;
-
- public String getUrl() {
- return url;
- }
- public void setUrl(String url) {
- this.url = url;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
-
-}
diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml b/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml
index bf4452da4a..16db00ace3 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml
+++ b/spring-boot-modules/spring-boot-properties/src/main/resources/configForProperties.xml
@@ -14,8 +14,4 @@
-
-
-
-
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties b/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties
index eb5703ca72..24bfdf2096 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties
+++ b/spring-boot-modules/spring-boot-properties/src/main/resources/database.properties
@@ -1,4 +1,3 @@
-
jdbc.url=jdbc:postgresql:/localhost:5432
database.username=foo
database.password=bar
diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml b/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml
index 8404d9411a..83432f65bc 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml
+++ b/spring-boot-modules/spring-boot-properties/src/main/resources/database.yml
@@ -1,5 +1,6 @@
database:
- url: jdbc:postresql:/localhost:5432/instance
+ jdbc:
+ url: jdbc:postresql:/localhost:5432
username: foo
password: bar
secret: foo
\ No newline at end of file
diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java
index 2b0833c387..3b80fa66fe 100644
--- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/ConfigPropertiesIntegrationTest.java
@@ -14,17 +14,13 @@ import com.baeldung.properties.AdditionalProperties;
import com.baeldung.properties.ConfigPropertiesDemoApplication;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class, DatabaseConfigPropertiesApp.class})
-@TestPropertySource(locations = {"classpath:configprops-test.properties", "classpath:database-test.properties"})
+@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class})
+@TestPropertySource(locations = {"classpath:configprops-test.properties"})
public class ConfigPropertiesIntegrationTest {
@Autowired
private ConfigProperties properties;
- @Autowired
- @Qualifier("dataSource")
- private Database databaseProperties;
-
@Autowired
private AdditionalProperties additionalProperties;
@@ -59,10 +55,4 @@ public class ConfigPropertiesIntegrationTest {
Assert.assertTrue(additionalProperties.getMax() == 100);
}
- @Test
- public void whenDatabasePropertyQueriedthenReturnsProperty() {
- Assert.assertTrue(databaseProperties.getUrl().equals("jdbc:postgresql:/localhost:5432"));
- Assert.assertTrue(databaseProperties.getUsername().equals("foo"));
- Assert.assertTrue(databaseProperties.getPassword().equals("bar"));
- }
}
diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/DatabasePropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/DatabasePropertiesIntegrationTest.java
index 0b9bd797ae..50a129916f 100644
--- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/DatabasePropertiesIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/configurationproperties/DatabasePropertiesIntegrationTest.java
@@ -4,26 +4,28 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.properties.ConfigPropertiesDemoApplication;
-import com.baeldung.properties.Database;
+import com.baeldung.configurationproperties.Database;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = ConfigPropertiesDemoApplication.class)
-@TestPropertySource("classpath:application.properties")
+@SpringBootTest(classes = DatabaseConfigPropertiesApp.class)
+@TestPropertySource("classpath:database-test.properties")
public class DatabasePropertiesIntegrationTest {
@Autowired
+ @Qualifier("dataSource")
private Database database;
@Test
public void testDatabaseProperties() {
Assert.assertNotNull(database);
- Assert.assertEquals("jdbc:postgresql:/localhost:5432/instance", database.getUrl());
+ Assert.assertEquals("jdbc:postgresql:/localhost:5432", database.getUrl());
Assert.assertEquals("foo", database.getUsername());
Assert.assertEquals("bar", database.getPassword());
}
diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties
index d4d1df7abc..af38556f81 100644
--- a/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties
+++ b/spring-boot-modules/spring-boot-properties/src/test/resources/application.properties
@@ -3,6 +3,3 @@ spring.properties.refreshDelay=1000
spring.config.location=file:extra.properties
spring.main.allow-bean-definition-overriding=true
-database.url=jdbc:postgresql:/localhost:5432/instance
-database.username=foo
-database.password=bar
\ No newline at end of file