Permalink
Browse files

Both @value and @ConfigurationProperties implemented to see the diffe…

…rences
  • Loading branch information...
penguinjournals committed Oct 9, 2017
1 parent 5936b08 commit 8846bf4f00101db4743aa096bcf8f1b9e08e3c63
View
@@ -1,3 +1,4 @@
.idea
target
bogindexer.iml
application.properties
@@ -3,18 +3,31 @@
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.*;
import org.springframework.beans.factory.annotation.*;
@SpringBootApplication
public class App implements CommandLineRunner
{
// The @Value approach
@Value("${greeting:DefaultValue}")
private String greeting;
// The @ConfigurationProperties approach
private final ConfigurationLoader configurationLoader;
@Autowired
public App(ConfigurationLoader configurationLoader) {
this.configurationLoader = configurationLoader;
}
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
@Override
public void run(String... strings) throws Exception {
System.out.println("Hello world");
System.out.println(configurationLoader.getGoodbye());
System.out.println(greeting);
}
}
@@ -0,0 +1,23 @@
package com.penguinjournals.bogindexer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Created by david on 08/10/2017.
*/
@Component
@ConfigurationProperties
public class ConfigurationLoader {
private String greeting;
private String goodbye;
public String getGoodbye() {
return goodbye;
}
public void setGoodbye(String goodbye) {
this.goodbye = goodbye;
}
}
@@ -0,0 +1,2 @@
greeting=Hello world
goodbye=See you
@@ -0,0 +1 @@
greeting=Hello world

0 comments on commit 8846bf4

Please sign in to comment.