Last active
March 9, 2019 11:20
-
-
Save rainoko/c948a5c5b63fb33ba2d65361ca425512 to your computer and use it in GitHub Desktop.
Simple spring boot application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bytetrain; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
@SpringBootApplication | |
public class Application implements CommandLineRunner { | |
private final EnvirontmentPrinter printer; | |
private static Logger LOG = LoggerFactory.getLogger(Application.class); | |
@Autowired | |
public Application(EnvirontmentPrinter printer) { | |
this.printer = printer; | |
} | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@Override | |
public void run(String... args) { | |
printer.print(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app: | |
param1: param1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bytetrain; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.EnvironmentAware; | |
import org.springframework.core.env.Environment; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class EnvironmentPrinter implements EnvironmentAware { | |
private static Logger LOG = LoggerFactory.getLogger(Application.class); | |
private Environment environment; | |
private final Properties properties; | |
@Autowired | |
public EnvironmentPrinter(Properties properties) { | |
this.properties = properties; | |
} | |
@Override | |
public void setEnvironment(Environment environment) { | |
this.environment = environment; | |
} | |
void print() { | |
String activeProfiles = String.join(",", environment.getActiveProfiles()); | |
LOG.info("Active profiles: {}", activeProfiles); | |
LOG.info("Properties: {}", properties); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bytetrain; | |
import lombok.Data; | |
import org.springframework.boot.context.properties.ConfigurationProperties; | |
import org.springframework.stereotype.Component; | |
@Component | |
@ConfigurationProperties(prefix = "app") | |
@Data | |
public class Properties { | |
private String param1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment