[BAEL-17473] - Moved articles to corrrect places, formatted pom.xmls and added description in readme files
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConfProperties {
|
||||
|
||||
@Value("${db.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${db.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${db.password}")
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
||||
@Configuration
|
||||
public class ExternalPropertyConfigurer {
|
||||
|
||||
@Bean
|
||||
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
PropertySourcesPlaceholderConfigurer properties = new PropertySourcesPlaceholderConfigurer();
|
||||
properties.setLocation(new FileSystemResource("src/main/resources/external/conf.properties"));
|
||||
properties.setIgnoreResourceNotFound(false);
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExternalPropertyFileLoader {
|
||||
|
||||
@Autowired
|
||||
ConfProperties prop;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(ExternalPropertyFileLoader.class).build()
|
||||
.run(args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
db.url=jdbc:postgresql://localhost:5432/
|
||||
db.username=admin
|
||||
db.password=root
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = ExternalPropertyFileLoader.class)
|
||||
public class ExternalPropertyFileLoaderIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ConfProperties props;
|
||||
|
||||
@Test
|
||||
public void whenExternalisedPropertiesLoaded_thenReadValues() throws IOException {
|
||||
assertEquals("jdbc:postgresql://localhost:5432/", props.getUrl());
|
||||
assertEquals("admin", props.getUsername());
|
||||
assertEquals("root", props.getPassword());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user