本文共 3214 字,大约阅读时间需要 10 分钟。
org.springframework.boot spring-boot-starter
package com.example;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Conditional;import org.springframework.context.annotation.Configuration;@Configuration@ConditionalOnWebApplication@EnableConfigurationProperties(HelloProperties.class)public class HelloAutoConfig { @Bean public Hello hello(){ Hello hello = new Hello(); return hello; }}
package com.example;import org.springframework.beans.factory.annotation.Autowired;public class Hello { @Autowired HelloProperties helloProperties; public String hello(String name){ return helloProperties.getPrefix() + "_" + name + "_" + helloProperties.suffix; }}
package com.example;import org.springframework.boot.context.properties.ConfigurationProperties;@ConfigurationProperties(prefix="huang.hel")public class HelloProperties { String prefix; String suffix; public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } public String getSuffix() { return suffix; } public void setSuffix(String suffix) { this.suffix = suffix; } }
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.example.HelloAutoConfig
com.example autoStart 0.0.1-SNAPSHOT
com.example autoStart 0.0.1-SNAPSHOT
com.example start 0.0.1-SNAPSHOT
com.example start 0.0.1-SNAPSHOT
package com.example.test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;import com.example.Hello;@RestControllerpublic class T2Listener{ @Autowired Hello hello; @GetMapping("/hello") public String aa(){ return hello.hello("dawwdaadw"); }}
huang: hel: prefix: shuaiuuuu suffix: ting
转载地址:http://kyern.baihongyu.com/