package com.gufang.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Enable Gufang DevTool for spring boot application
*
* @author chen.qixiang
* @version 1.0.0
* @since 1.0.0
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EnableGufangConfiguration {
}
package com.gufang.boot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.gufang.annotation.EnableGufangConfiguration;
@Configuration
@ConditionalOnBean(annotation = EnableGufangConfiguration.class)
@EnableConfigurationProperties(GufangProperties.class)
public class GufangConfiguration {
@Autowired
private GufangProperties properties;
@Bean
public Object createBean()
{
System.out.println("Gufang="+properties);
return new Object();
}
}
package com.gufang.boot.context.event;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import com.gufang.annotation.EnableGufangConfiguration;
public class GufangBannerApplicationListener implements
ApplicationListener<ApplicationEnvironmentPreparedEvent>
{
public static String gufangLogo =
" ###################################################################################### \n" +
" ######## # # ######## \n" +
" ######## ######## ######### ### # # #### ##### ##### ######## \n" +
" ######## # # # # # ## # # # ######## \n" +
" ######## ##### ###### # # # # # # ##### ##### ######## \n" +
" ######## # # # # # # # # # # # # ######## \n" +
" ######## ##### # # # # # # # #### ##### # # ######## \n" +
" ###################################################################################### \n" +
" \n" +
"\n";
public static String LINE_SEPARATOR = System.getProperty("line.separator");
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
System.out.println(buildBannerText());
}
private String buildBannerText() {
StringBuilder bannerTextBuilder = new StringBuilder();
bannerTextBuilder.append(LINE_SEPARATOR).append(gufangLogo).append(" :: Gufang :: (v1.0.0)")
.append(LINE_SEPARATOR);
return bannerTextBuilder.toString();
}
}
spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.gufang.boot.GufangConfiguration
org.springframework.context.ApplicationListener=\
com.gufang.boot.context.event.GufangBannerApplicationListener
spring.provides
provides: gufang-spring-boot-starter