|
1 | 1 | /* |
2 | | - * Copyright 2012-2015 the original author or authors. |
| 2 | + * Copyright 2012-2016 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package sample.propertyvalidation; |
18 | 18 |
|
19 | | -import org.springframework.beans.factory.annotation.Autowired; |
20 | 19 | import org.springframework.boot.CommandLineRunner; |
21 | 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
22 | 21 | import org.springframework.boot.builder.SpringApplicationBuilder; |
23 | 22 | import org.springframework.context.annotation.Bean; |
24 | | -import org.springframework.context.annotation.Profile; |
25 | | -import org.springframework.stereotype.Service; |
26 | 23 | import org.springframework.validation.Validator; |
27 | 24 |
|
28 | 25 | @SpringBootApplication |
29 | | -public class SamplePropertyValidationApplication { |
| 26 | +public class SamplePropertyValidationApplication implements CommandLineRunner { |
| 27 | + |
| 28 | + private final SampleProperties properties; |
| 29 | + |
| 30 | + public SamplePropertyValidationApplication(SampleProperties properties) { |
| 31 | + this.properties = properties; |
| 32 | + } |
30 | 33 |
|
31 | 34 | @Bean |
32 | | - public Validator configurationPropertiesValidator() { |
| 35 | + public static Validator configurationPropertiesValidator() { |
33 | 36 | return new SamplePropertiesValidator(); |
34 | 37 | } |
35 | 38 |
|
36 | | - @Service |
37 | | - @Profile("app") |
38 | | - static class Startup implements CommandLineRunner { |
39 | | - |
40 | | - @Autowired |
41 | | - private SampleProperties properties; |
42 | | - |
43 | | - @Override |
44 | | - public void run(String... args) { |
45 | | - System.out.println("========================================="); |
46 | | - System.out.println("Sample host: " + this.properties.getHost()); |
47 | | - System.out.println("Sample port: " + this.properties.getPort()); |
48 | | - System.out.println("========================================="); |
49 | | - } |
| 39 | + @Override |
| 40 | + public void run(String... args) { |
| 41 | + System.out.println("========================================="); |
| 42 | + System.out.println("Sample host: " + this.properties.getHost()); |
| 43 | + System.out.println("Sample port: " + this.properties.getPort()); |
| 44 | + System.out.println("========================================="); |
50 | 45 | } |
51 | 46 |
|
52 | 47 | public static void main(String[] args) throws Exception { |
53 | | - new SpringApplicationBuilder(SamplePropertyValidationApplication.class) |
54 | | - .profiles("app").run(args); |
| 48 | + new SpringApplicationBuilder(SamplePropertyValidationApplication.class).run(args); |
55 | 49 | } |
56 | 50 |
|
57 | 51 | } |
0 commit comments