{"id":15876,"date":"2026-04-25T00:35:28","date_gmt":"2026-04-24T16:35:28","guid":{"rendered":"https:\/\/top.duoku.icu\/libs\/15876.html"},"modified":"2026-04-25T00:35:28","modified_gmt":"2026-04-24T16:35:28","slug":"spring-boot-%e4%ba%8c%e6%ac%a1%e5%bc%80%e5%8f%91%e8%af%a6%e8%a7%a3%ef%bc%9a%e4%bb%8e%e8%87%aa%e5%ae%9a%e4%b9%89-starter-%e5%88%b0%e6%a1%86%e6%9e%b6%e6%89%a9%e5%b1%95-6","status":"publish","type":"post","link":"https:\/\/www.srclibs.com\/index.php\/2026\/04\/25\/spring-boot-%e4%ba%8c%e6%ac%a1%e5%bc%80%e5%8f%91%e8%af%a6%e8%a7%a3%ef%bc%9a%e4%bb%8e%e8%87%aa%e5%ae%9a%e4%b9%89-starter-%e5%88%b0%e6%a1%86%e6%9e%b6%e6%89%a9%e5%b1%95-6\/","title":{"rendered":"Spring Boot \u4e8c\u6b21\u5f00\u53d1\u8be6\u89e3\uff1a\u4ece\u81ea\u5b9a\u4e49 Starter \u5230\u6846\u67b6\u6269\u5c55"},"content":{"rendered":"<div style=\"text-align:center;margin:30px 0;\"><img decoding=\"async\" src=\"https:\/\/top.duoku.icu\/wp-content\/uploads\/2026\/04\/image-66.png\" alt=\"Spring Boot \u4e8c\u6b21\u5f00\u53d1\u8be6\u89e3\uff1a\u4ece\u81ea\u5b9a\u4e49 Starter \u5230\u6846\u67b6\u6269\u5c55\" style=\"max-width:100%;height:auto;border-radius:12px;box-shadow:0 4px 12px rgba(0,0,0,0.1);\"><\/div>\n<p># Spring Boot \u4e8c\u6b21\u5f00\u53d1\u8be6\u89e3\uff1a\u4ece\u81ea\u5b9a\u4e49 Starter \u5230\u6846\u67b6\u6269\u5c55<\/p>\n<p>## \u4e00\u3001Spring Boot \u7b80\u4ecb\u4e0e\u4e8c\u6b21\u5f00\u53d1\u4ef7\u503c<\/p>\n<p>Spring Boot \u662f\u7531 Pivotal \u56e2\u961f\u63d0\u4f9b\u7684\u5168\u65b0\u6846\u67b6\uff0c\u5176\u8bbe\u8ba1\u76ee\u7684\u662f\u7528\u6765\u7b80\u5316\u65b0 Spring \u5e94\u7528\u7684\u521d\u59cb\u642d\u5efa\u4ee5\u53ca\u5f00\u53d1\u8fc7\u7a0b\u3002<\/p>\n<p>### \u4e8c\u6b21\u5f00\u53d1\u7684\u6838\u5fc3\u4ef7\u503c<\/p>\n<p>&#8211; **\u7edf\u4e00\u89c4\u8303**\uff1a\u5728\u4f01\u4e1a\u4e2d\u5efa\u7acb\u7edf\u4e00\u7684\u5f00\u53d1\u6807\u51c6\u548c\u6700\u4f73\u5b9e\u8df5<br \/>\n&#8211; **\u7b80\u5316\u6d41\u7a0b**\uff1a\u5c01\u88c5\u5e38\u7528\u529f\u80fd\uff0c\u964d\u4f4e\u5f00\u53d1\u590d\u6742\u5ea6<br \/>\n&#8211; **\u5feb\u901f\u590d\u7528**\uff1a\u901a\u8fc7 Starter \u5feb\u901f\u590d\u7528\u5df2\u9a8c\u8bc1\u7684\u529f\u80fd\u6a21\u5757<br \/>\n&#8211; **\u96c6\u4e2d\u7ba1\u7406**\uff1a\u7edf\u4e00\u7ba1\u7406\u4f9d\u8d56\u7248\u672c\u3001\u914d\u7f6e\u9879\u548c\u7ec4\u4ef6\u521d\u59cb\u5316<\/p>\n<p>### \u9002\u7528\u573a\u666f<\/p>\n<p>1. \u4f01\u4e1a\u7ea7\u6846\u67b6\u5b9a\u5236<br \/>\n2. \u5185\u90e8\u7ec4\u4ef6\u5c01\u88c5<br \/>\n3. \u901a\u7528\u529f\u80fd\u6a21\u5757\u5316<br \/>\n4. \u6280\u672f\u6808\u6807\u51c6\u5316<\/p>\n<p>## \u4e8c\u3001\u81ea\u5b9a\u4e49 Starter \u5f00\u53d1<\/p>\n<p>### 1. Starter \u7684\u7ed3\u6784<\/p>\n<p>\u4e00\u4e2a\u6807\u51c6\u7684 Starter \u5305\u542b\u4ee5\u4e0b\u90e8\u5206\uff1a<\/p>\n<p>&#8220;`<br \/>\nmy-spring-starter<br \/>\n\u251c\u2500\u2500 src\/main\/java<br \/>\n\u2502   \u2514\u2500\u2500 com.example<br \/>\n\u2502       \u251c\u2500\u2500 MyAutoConfiguration.java<br \/>\n\u2502       \u251c\u2500\u2500 MyProperties.java<br \/>\n\u2502       \u2514\u2500\u2500 MyStarterApplication.java<br \/>\n\u251c\u2500\u2500 src\/main\/resources<br \/>\n\u2502   \u2514\u2500\u2500 META-INF<br \/>\n\u2502       \u2514\u2500\u2500 spring.factories<br \/>\n\u2514\u2500\u2500 pom.xml<br \/>\n&#8220;`<\/p>\n<p>### 2. Spring.factories \u914d\u7f6e<\/p>\n<p>&#8220;`properties<br \/>\n# src\/main\/resources\/META-INF\/spring.factories<\/p>\n<p>org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\<br \/>\ncom.example.MyAutoConfiguration<br \/>\n&#8220;`<\/p>\n<p>### 3. \u81ea\u52a8\u914d\u7f6e\u7c7b<\/p>\n<p>&#8220;`java<br \/>\n@Configuration<br \/>\n@ConditionalOnClass(MyService.class)<br \/>\n@ConditionalOnMissingBean(MyService.class)<br \/>\n@EnableConfigurationProperties(MyProperties.class)<br \/>\npublic class MyAutoConfiguration {<\/p>\n<p>    @Bean<br \/>\n    @ConfigurationProperties(prefix = &#8220;my&#8221;)<br \/>\n    public MyProperties myProperties() {<br \/>\n        return new MyProperties();<br \/>\n    }<\/p>\n<p>    @Bean<br \/>\n    public MyService myService(MyProperties properties) {<br \/>\n        return new MyService(properties);<br \/>\n    }<\/p>\n<p>    @Bean<br \/>\n    @ConditionalOnProperty(prefix = &#8220;my&#8221;, name = &#8220;enabled&#8221;, havingValue = &#8220;true&#8221;)<br \/>\n    public MyController myController(MyService service) {<br \/>\n        return new MyController(service);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>## \u4e09\u3001Auto Configuration \u539f\u7406<\/p>\n<p>### 1. \u81ea\u52a8\u914d\u7f6e\u52a0\u8f7d\u6d41\u7a0b<\/p>\n<p>&#8220;`java<br \/>\n@SpringBootApplication<br \/>\npublic class Application {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ @SpringBootApplication \u5305\u542b @EnableAutoConfiguration<br \/>\n        SpringApplication.run(Application.class, args);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u6838\u5fc3\u6ce8\u89e3\u89e3\u6790<\/p>\n<p>&#8220;`java<br \/>\n@AutoConfigurationPackage<br \/>\n@Import(AutoConfigurationImportSelector.class)<br \/>\npublic @interface EnableAutoConfiguration {<br \/>\n    String ENABLED_OVERRIDE_ATTR = &#8220;spring.boot.enableautoconfiguration&#8221;;<\/p>\n<p>    @AliasFor(annotation = ImportSelector.class)<br \/>\n    String[] exclude() default {};<\/p>\n<p>    @AliasFor(annotation = ImportSelector.class)<br \/>\n    String[] excludeName() default {};<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 3. \u6761\u4ef6\u6ce8\u89e3\u8be6\u89e3<\/p>\n<p>&#8220;`java<br \/>\n\/\/ 1. \u7c7b\u5b58\u5728\u6761\u4ef6<br \/>\n@ConditionalOnClass(String.class)<\/p>\n<p>\/\/ 2. \u7c7b\u4e0d\u5b58\u5728\u6761\u4ef6<br \/>\n@ConditionalOnMissingClass(&#8220;com.example.NotFoundClass&#8221;)<\/p>\n<p>\/\/ 3. Bean \u5b58\u5728\u6761\u4ef6<br \/>\n@ConditionalOnBean(MyService.class)<\/p>\n<p>\/\/ 4. Bean \u4e0d\u5b58\u5728\u6761\u4ef6<br \/>\n@ConditionalOnMissingBean(MyService.class)<\/p>\n<p>\/\/ 5. \u5c5e\u6027\u6761\u4ef6<br \/>\n@ConditionalOnProperty(prefix = &#8220;my&#8221;, name = &#8220;enabled&#8221;)<\/p>\n<p>\/\/ 6. \u8d44\u6e90\u6761\u4ef6<br \/>\n@ConditionalOnResource(resources = &#8220;classpath:config.properties&#8221;)<\/p>\n<p>\/\/ 7. \u8868\u8fbe\u5f0f\u6761\u4ef6<br \/>\n@ConditionalOnExpression(&#8220;${my.enabled:false} == true&#8221;)<br \/>\n&#8220;`<\/p>\n<p>## \u56db\u3001\u81ea\u5b9a\u4e49 Starter \u5b9e\u6218<\/p>\n<p>### 1. \u5b8c\u6574 Starter \u793a\u4f8b<\/p>\n<p>&#8220;`java<br \/>\n\/\/ MyProperties.java<br \/>\n@ConfigurationProperties(prefix = &#8220;my-starter&#8221;)<br \/>\npublic class MyProperties {<\/p>\n<p>    private boolean enabled = true;<br \/>\n    private String apiKey;<br \/>\n    private int timeout = 3000;<\/p>\n<p>    \/\/ Getters and Setters<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>&#8220;`java<br \/>\n\/\/ MyAutoConfiguration.java<br \/>\n@Configuration<br \/>\n@ConditionalOnProperty(name = &#8220;my-starter.enabled&#8221;)<br \/>\n@EnableConfigurationProperties(MyProperties.class)<br \/>\npublic class MyAutoConfiguration {<\/p>\n<p>    @Autowired<br \/>\n    private MyProperties properties;<\/p>\n<p>    @Bean<br \/>\n    public MyApiClient myApiClient() {<br \/>\n        return new MyApiClient(properties.getApiKey(), properties.getTimeout());<br \/>\n    }<\/p>\n<p>    @Bean<br \/>\n    @ConditionalOnMissingBean<br \/>\n    public MyService myService(MyApiClient client) {<br \/>\n        return new MyService(client);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>&#8220;`java<br \/>\n\/\/ MyApiClient.java<br \/>\npublic class MyApiClient {<\/p>\n<p>    private final String apiKey;<br \/>\n    private final int timeout;<\/p>\n<p>    public MyApiClient(String apiKey, int timeout) {<br \/>\n        this.apiKey = apiKey;<br \/>\n        this.timeout = timeout;<br \/>\n    }<\/p>\n<p>    public String fetchData(String url) {<br \/>\n        \/\/ \u5b9e\u73b0 HTTP \u8bf7\u6c42\u903b\u8f91<br \/>\n        return &#8220;data&#8221;;<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>&#8220;`java<br \/>\n\/\/ MyService.java<br \/>\n@Service<br \/>\npublic class MyService {<\/p>\n<p>    private final MyApiClient apiClient;<\/p>\n<p>    public MyService(MyApiClient apiClient) {<br \/>\n        this.apiClient = apiClient;<br \/>\n    }<\/p>\n<p>    public String getData() {<br \/>\n        return apiClient.fetchData(&#8220;https:\/\/api.example.com\/data&#8221;);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>&#8220;`java<br \/>\n\/\/ MyController.java<br \/>\n@RestController<br \/>\n@RequestMapping(&#8220;\/my&#8221;)<br \/>\npublic class MyController {<\/p>\n<p>    private final MyService myService;<\/p>\n<p>    public MyController(MyService myService) {<br \/>\n        this.myService = myService;<br \/>\n    }<\/p>\n<p>    @GetMapping(&#8220;\/data&#8221;)<br \/>\n    public String getData() {<br \/>\n        return myService.getData();<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u4f7f\u7528\u573a\u666f<\/p>\n<p>&#8220;`yaml<br \/>\n# application.yml<br \/>\nmy-starter:<br \/>\n  enabled: true<br \/>\n  api-key: your-api-key<br \/>\n  timeout: 5000<br \/>\n&#8220;`<\/p>\n<p>## \u4e94\u3001\u6269\u5c55 Spring Boot Actuator<\/p>\n<p>### 1. \u81ea\u5b9a\u4e49\u5065\u5eb7\u68c0\u67e5<\/p>\n<p>&#8220;`java<br \/>\n@Component<br \/>\npublic class CustomHealthIndicator implements HealthIndicator {<\/p>\n<p>    @Autowired<br \/>\n    private MyService myService;<\/p>\n<p>    @Override<br \/>\n    public Health health() {<br \/>\n        try {<br \/>\n            \/\/ \u68c0\u67e5\u670d\u52a1\u72b6\u6001<br \/>\n            String result = myService.getData();<\/p>\n<p>            if (result != null &#038;&#038; !result.isEmpty()) {<br \/>\n                return Health.up()<br \/>\n                    .withDetail(&#8220;service&#8221;, &#8220;healthy&#8221;)<br \/>\n                    .withDetail(&#8220;lastCheck&#8221;, System.currentTimeMillis())<br \/>\n                    .build();<br \/>\n            }<\/p>\n<p>            return Health.down()<br \/>\n                .withDetail(&#8220;service&#8221;, &#8220;no data&#8221;)<br \/>\n                .build();<\/p>\n<p>        } catch (Exception e) {<br \/>\n            return Health.down(e)<br \/>\n                .withDetail(&#8220;error&#8221;, e.getMessage())<br \/>\n                .build();<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u81ea\u5b9a\u4e49 Endpoint<\/p>\n<p>&#8220;`java<br \/>\n@RestController<br \/>\n@RequestMapping(&#8220;\/custom&#8221;)<br \/>\npublic class CustomEndpoint extends AbstractDelegatingExposableEndpoint<Map<String, Object>> {<\/p>\n<p>    private final MyService myService;<\/p>\n<p>    public CustomEndpoint(MyService myService) {<br \/>\n        super(&#8220;custom&#8221;);<br \/>\n        this.myService = myService;<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    protected Map<String, Object> invoke() {<br \/>\n        Map<String, Object> result = new HashMap<>();<br \/>\n        result.put(&#8220;status&#8221;, &#8220;running&#8221;);<br \/>\n        result.put(&#8220;service&#8221;, myService.getData());<br \/>\n        result.put(&#8220;timestamp&#8221;, System.currentTimeMillis());<br \/>\n        return result;<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 3. \u81ea\u5b9a\u4e49 Metric<\/p>\n<p>&#8220;`java<br \/>\n@Component<br \/>\npublic class CustomMetrics {<\/p>\n<p>    private final MeterRegistry meterRegistry;<\/p>\n<p>    public CustomMetrics(MeterRegistry meterRegistry) {<br \/>\n        this.meterRegistry = meterRegistry;<\/p>\n<p>        \/\/ \u6ce8\u518c\u81ea\u5b9a\u4e49\u6307\u6807<br \/>\n        Counter counter = Counter.builder(&#8220;my.service.calls&#8221;)<br \/>\n            .description(&#8220;My service call count&#8221;)<br \/>\n            .register(meterRegistry);<\/p>\n<p>        meterRegistry.gauge(&#8220;my.service.latency&#8221;,<br \/>\n            () -> myService.getLatency());<br \/>\n    }<\/p>\n<p>    public void recordCall() {<br \/>\n        meterRegistry.counter(&#8220;my.service.calls&#8221;).increment();<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>## \u516d\u3001CLI \u5de5\u5177\u5f00\u53d1<\/p>\n<p>### 1. Spring Boot CLI \u5e94\u7528<\/p>\n<p>&#8220;`groovy<br \/>\n\/\/ MyTool.groovy<br \/>\n#!\/usr\/bin\/env groovy<\/p>\n<p>@Grab(&#8216;org.springframework.boot:spring-boot-starter:3.1.0&#8217;)<br \/>\n@Grab(&#8216;com.fasterxml.jackson.core:jackson-databind:2.15.0&#8217;)<\/p>\n<p>import groovy.json.JsonSlurper<\/p>\n<p>class MyTool {<\/p>\n<p>    static void main(String[] args) {<br \/>\n        def tool = new MyTool()<br \/>\n        tool.run(args)<br \/>\n    }<\/p>\n<p>    def run(String[] args) {<br \/>\n        switch(args[0]) {<br \/>\n            case &#8216;generate&#8217;:<br \/>\n                generateConfig(args[1])<br \/>\n                break<br \/>\n            case &#8216;validate&#8217;:<br \/>\n                validateConfig(args[1])<br \/>\n                break<br \/>\n            default:<br \/>\n                println &#8216;Usage: mytool <command> [args]&#8217;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    def generateConfig(String output) {<br \/>\n        def config = [<br \/>\n            appName: &#8216;My Application&#8217;,<br \/>\n            version: &#8216;1.0.0&#8217;,<br \/>\n            environment: &#8216;development&#8217;,<br \/>\n            settings: [<br \/>\n                timeout: 3000,<br \/>\n                retries: 3<br \/>\n            ]<br \/>\n        ]<\/p>\n<p>        def writer = new FileWriter(output)<br \/>\n        def json = new JsonOutput().toJson(config)<br \/>\n        writer.write(json)<br \/>\n        writer.close()<\/p>\n<p>        println &#8220;Config generated: $output&#8221;<br \/>\n    }<\/p>\n<p>    def validateConfig(String input) {<br \/>\n        def reader = new FileReader(input)<br \/>\n        def json = new JsonSlurper().parseText(reader.text)<\/p>\n<p>        if (!json.appName || !json.version) {<br \/>\n            throw new IllegalArgumentException(&#8216;Invalid config&#8217;)<br \/>\n        }<\/p>\n<p>        println &#8216;Config is valid&#8217;<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u6253\u5305\u53ef\u6267\u884c CLI<\/p>\n<p>&#8220;`xml<br \/>\n<!-- pom.xml --><br \/>\n<build>\n    <plugins>\n        <plugin>\n            <groupId>org.codehaus.gmavenplus<\/groupId><br \/>\n            <artifactId>gmavenplus-plugin<\/artifactId><br \/>\n            <version>3.0.0<\/version><br \/>\n            <executions><br \/>\n                <execution><br \/>\n                    <goals><br \/>\n                        <goal>execute<\/goal><br \/>\n                    <\/goals><br \/>\n                <\/execution><br \/>\n            <\/executions>\n        <\/plugin>\n        <plugin>\n            <groupId>org.springframework.boot<\/groupId><br \/>\n            <artifactId>spring-boot-maven-plugin<\/artifactId>\n        <\/plugin>\n    <\/plugins>\n<\/build><br \/>\n&#8220;`<\/p>\n<p>## \u4e03\u3001\u6a21\u677f\u5f15\u64ce\u5b9a\u5236<\/p>\n<p>### 1. \u81ea\u5b9a\u4e49 Thymeleaf \u5904\u7406\u5668<\/p>\n<p>&#8220;`java<br \/>\n@Configuration<br \/>\npublic class CustomThymeleafConfig implements WebMvcConfigurer {<\/p>\n<p>    @Autowired<br \/>\n    private ApplicationContext applicationContext;<\/p>\n<p>    @Bean<br \/>\n    public SpringViewResolver viewResolver() {<br \/>\n        SpringViewResolver resolver = new SpringViewResolver();<br \/>\n        resolver.setViewResolvers(applicationContext.getBeanFactory()<br \/>\n            .getBeansOfType(ViewResolver.class).values());<br \/>\n        return resolver;<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u81ea\u5b9a\u4e49 Thymeleaf \u8868\u8fbe\u5f0f<\/p>\n<p>&#8220;`java<br \/>\n@Component<br \/>\npublic class CustomExpressionObjectFactory implements ExpressionObjectFactory {<\/p>\n<p>    private final CustomTemplateHelper helper;<\/p>\n<p>    public CustomExpressionObjectFactory(CustomTemplateHelper helper) {<br \/>\n        this.helper = helper;<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    public ExpressionObject createExpressionObject(SpringContext context) {<br \/>\n        return new CustomExpressionObject(context, helper);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 3. \u81ea\u5b9a\u4e49\u6a21\u677f\u5f15\u64ce<\/p>\n<p>&#8220;`java<br \/>\n@Component<br \/>\npublic class CustomTemplateEngine {<\/p>\n<p>    private final TemplateEngine templateEngine;<\/p>\n<p>    public CustomTemplateEngine() {<br \/>\n        this.templateEngine = new SpringTemplateEngine();<\/p>\n<p>        \/\/ \u6dfb\u52a0\u65b9\u8a00<br \/>\n        templateEngine.setDialect(new SpringStandardDialect());<\/p>\n<p>        \/\/ \u6dfb\u52a0\u5904\u7406\u5668<br \/>\n        templateEngine.addTemplateResolver(new ClassLoaderTemplateResolver());<br \/>\n        templateEngine.addTemplateResolver(new ServletContextTemplateResolver());<br \/>\n    }<\/p>\n<p>    public String process(String templateName, Context context) {<br \/>\n        return templateEngine.process(templateName, context);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>## \u516b\u3001\u6700\u4f73\u5b9e\u8df5\u4e0e\u6ce8\u610f\u4e8b\u9879<\/p>\n<p>### 1. Starter \u5f00\u53d1\u6700\u4f73\u5b9e\u8df5<\/p>\n<p>&#8220;`java<br \/>\n\/\/ \u2705 \u6b63\u786e\uff1a\u4f7f\u7528\u6761\u4ef6\u6ce8\u89e3<br \/>\n@Configuration<br \/>\n@ConditionalOnClass(Service.class)<br \/>\n@ConditionalOnMissingBean(Service.class)<br \/>\npublic class MyAutoConfiguration {<br \/>\n    @Bean<br \/>\n    public Service service() {<br \/>\n        return new Service();<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u274c \u9519\u8bef\uff1a\u65e0\u6761\u4ef6\u6ce8\u518c Bean<br \/>\n@Configuration<br \/>\npublic class MyAutoConfiguration {<br \/>\n    @Bean<br \/>\n    public Service service() {<br \/>\n        return new Service(); \/\/ \u53ef\u80fd\u8986\u76d6\u7528\u6237\u914d\u7f6e<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 2. \u914d\u7f6e\u5c5e\u6027\u7ba1\u7406<\/p>\n<p>&#8220;`java<br \/>\n\/\/ \u2705 \u6b63\u786e\uff1a\u4f7f\u7528@ConfigurationProperties<br \/>\n@ConfigurationProperties(prefix = &#8220;my&#8221;)<br \/>\npublic class MyProperties {<br \/>\n    private String name;<br \/>\n    private int timeout = 3000;<br \/>\n}<\/p>\n<p>\/\/ \u274c \u9519\u8bef\uff1a\u786c\u7f16\u7801\u914d\u7f6e<br \/>\npublic class MyService {<br \/>\n    private static final String API_KEY = &#8220;xxx&#8221;;<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 3. \u4f9d\u8d56\u7ba1\u7406<\/p>\n<p>&#8220;`xml<br \/>\n<!-- \u2705 \u6b63\u786e\uff1a\u4f7f\u7528 provided \u8303\u56f4 --><br \/>\n<dependency><br \/>\n    <groupId>org.springframework.boot<\/groupId><br \/>\n    <artifactId>spring-boot-autoconfigure<\/artifactId><br \/>\n    <scope>provided<\/scope><br \/>\n<\/dependency><\/p>\n<p><!-- \u274c \u9519\u8bef\uff1a\u76f4\u63a5\u5f15\u7528\u5177\u4f53\u7248\u672c --><br \/>\n<dependency><br \/>\n    <groupId>com.example<\/groupId><br \/>\n    <artifactId>some-lib<\/artifactId><br \/>\n    <version>1.0.0<\/version><br \/>\n<\/dependency><br \/>\n&#8220;`<\/p>\n<p>### 4. \u6d4b\u8bd5\u7b56\u7565<\/p>\n<p>&#8220;`java<br \/>\n@SpringBootTest(classes = MyAutoConfiguration.class)<br \/>\n@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY)<br \/>\npublic class MyAutoConfigurationTest {<\/p>\n<p>    @Autowired<br \/>\n    private MyService myService;<\/p>\n<p>    @Test<br \/>\n    public void testService() {<br \/>\n        assertNotNull(myService);<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>### 5. \u7248\u672c\u517c\u5bb9\u6027<\/p>\n<p>&#8220;`java<br \/>\n\/\/ \u2705 \u6b63\u786e\uff1a\u4f7f\u7528\u7248\u672c\u5bfc\u5165<br \/>\n<dependencyManagement><br \/>\n    <dependencies><br \/>\n        <dependency><br \/>\n            <groupId>org.springframework.boot<\/groupId><br \/>\n            <artifactId>spring-boot-dependencies<\/artifactId><br \/>\n            <version>3.1.0<\/version><br \/>\n            <type>pom<\/type><br \/>\n            <scope>import<\/scope><br \/>\n        <\/dependency><br \/>\n    <\/dependencies><br \/>\n<\/dependencyManagement><br \/>\n&#8220;`<\/p>\n<p>## \u603b\u7ed3<\/p>\n<p>Spring Boot \u4e8c\u6b21\u5f00\u53d1\u80fd\u591f\u6781\u5927\u63d0\u5347\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002\u901a\u8fc7\u81ea\u5b9a\u4e49 Starter\uff0c\u53ef\u4ee5\u5c01\u88c5\u901a\u7528\u529f\u80fd\uff0c\u5efa\u7acb\u4f01\u4e1a\u7ea7\u5f00\u53d1\u6807\u51c6\u3002<\/p>\n<p>**\u6838\u5fc3\u8981\u70b9\u56de\u987e\uff1a**<br \/>\n&#8211; \u2705 \u7406\u89e3 Auto Configuration \u539f\u7406<br \/>\n&#8211; \u2705 \u638c\u63e1\u81ea\u5b9a\u4e49 Starter \u5f00\u53d1<br \/>\n&#8211; \u2705 \u6269\u5c55 Actuator \u529f\u80fd<br \/>\n&#8211; \u2705 \u5f00\u53d1 CLI \u5de5\u5177<br \/>\n&#8211; \u2705 \u9075\u5faa\u6700\u4f73\u5b9e\u8df5<\/p>\n<div style=\"text-align:center;margin:30px 0;\">\n<p style=\"color:#666;font-size:14px;\">#SpringBoot #Java #\u4e8c\u6b21\u5f00\u53d1 #\u5fae\u670d\u52a1 #\u6846\u67b6\u5b9a\u5236 #\u81ea\u52a8\u5316\u914d\u7f6e<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p># Spring Boot \u4e8c\u6b21\u5f00\u53d1\u8be6\u89e3\uff1a\u4ece\u81ea\u5b9a\u4e49 Starter \u5230\u6846\u67b6\u6269\u5c55 ## \u4e00\u3001Spring Boo&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-15876","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/comments?post=15876"}],"version-history":[{"count":0,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15876\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/media?parent=15876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/categories?post=15876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/tags?post=15876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}