添加代码示例springboot-starter
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
package com.xncoding.starter;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.xncoding.starter.config;
|
||||
|
||||
import com.xncoding.starter.service.ExampleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* ExampleAutoConfigure
|
||||
*
|
||||
* @author XiongNeng
|
||||
* @version 1.0
|
||||
* @since 2018/2/28
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(ExampleService.class)
|
||||
@EnableConfigurationProperties(ExampleServiceProperties.class)
|
||||
public class ExampleAutoConfigure {
|
||||
|
||||
private final ExampleServiceProperties properties;
|
||||
|
||||
@Autowired
|
||||
public ExampleAutoConfigure(ExampleServiceProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(prefix = "example.service", value = "enabled",havingValue = "true")
|
||||
ExampleService exampleService (){
|
||||
return new ExampleService(properties.getPrefix(),properties.getSuffix());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.xncoding.starter.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* ExampleServiceProperties
|
||||
*
|
||||
* @author XiongNeng
|
||||
* @version 1.0
|
||||
* @since 2018/2/28
|
||||
*/
|
||||
@ConfigurationProperties("example.service")
|
||||
public class ExampleServiceProperties {
|
||||
private String prefix;
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.xncoding.starter.service;
|
||||
|
||||
/**
|
||||
* ExampleService
|
||||
*
|
||||
* @author XiongNeng
|
||||
* @version 1.0
|
||||
* @since 2018/2/28
|
||||
*/
|
||||
public class ExampleService {
|
||||
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
|
||||
public ExampleService(String prefix, String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
public String wrap(String word) {
|
||||
return prefix + word + suffix;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.xncoding.starter.config.ExampleAutoConfigure
|
||||
Reference in New Issue
Block a user