[BAEL-17473] - Initial commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.webjar;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@GetMapping(value = "/")
|
||||
public String welcome(Model model) {
|
||||
return "index";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.webjar;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WebjarsdemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebjarsdemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
4
spring-boot-artifacts/src/main/resources/external/conf.properties
vendored
Normal file
4
spring-boot-artifacts/src/main/resources/external/conf.properties
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
db.url=jdbc:postgresql://localhost:5432/
|
||||
db.username=admin
|
||||
db.password=root
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
13
spring-boot-artifacts/src/main/resources/logback.xml
Normal file
13
spring-boot-artifacts/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>WebJars Demo</title>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome Home</h1>
|
||||
<div class="container"><br/>
|
||||
<div class="alert alert-success">
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||
<strong>Success!</strong> It is working as we expected.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
|
||||
<script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.webjar;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = WebjarsdemoApplication.class)
|
||||
@WebAppConfiguration
|
||||
public class WebjarsdemoApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user