@Configuration @ConditionalOnClass(DataSource.class) @EnableConfigurationProperties(MyLibraryProperties.class) public class MyLibraryAutoConfiguration { @Autowired private MyLibraryProperties properties; @Bean public MyLibraryService myLibraryService() { return new MyLibraryService(properties); } } @ConfigurationProperties(prefix = "mylibrary") public class MyLibraryProperties { private String message = "Hello, World!"; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } } org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.example.MyLibraryAutoConfiguration @RestController public class MyController { @Autowired private MyLibraryService myLibraryService; @GetMapping("/") public String hello() { return myLibraryService.getMessage(); } } properties mylibrary.message=Welcome to Spring Boot!


上一篇:
下一篇:
切换中文