本文整理汇总了Java中org.springframework.boot.context.properties.EnableConfigurationProperties类的典型用法代码示例。如果您正苦于以下问题:Java EnableConfigurationProperties类的具体用法?Java EnableConfigurationProperties怎么用?Java EnableConfigurationProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnableConfigurationProperties类属于org.springframework.boot.context.properties包,在下文中一共展示了EnableConfigurationProperties类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createComponentAutoConfigurationSource
import org.springframework.boot.context.properties.EnableConfigurationProperties; //导入依赖的package包/类
private void createComponentAutoConfigurationSource(String packageName, ComponentModel model) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Component", "ComponentAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
String configurationName = name.replace("ComponentAutoConfiguration", "ComponentConfiguration");
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
// add method for auto configure
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
String body = createComponentBody(model.getShortJavaType());
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod()
.setName(methodName)
.setPublic()
.setBody(body)
.setReturnType(model.getShortJavaType())
.addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
method.addAnnotation(Bean.class);
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
File target = new File(srcDir, fileName);
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
String header = loadText(is);
String code = sourceToString(javaClass);
code = header + code;
getLog().debug("Source code generated:\n" + code);
if (target.exists()) {
String existing = FileUtils.readFileToString(target);
if (!code.equals(existing)) {
FileUtils.write(target, code, false);
getLog().info("Updated existing file: " + target);
} else {
getLog().debug("No changes to existing file: " + target);
}
} else {
FileUtils.write(target, code);
getLog().info("Created file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}
示例2: createDataFormatAutoConfigurationSource
import org.springframework.boot.context.properties.EnableConfigurationProperties; //导入依赖的package包/类
private void createDataFormatAutoConfigurationSource(String packageName, DataFormatModel model) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("DataFormat", "DataFormatAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
String configurationName = name.replace("DataFormatAutoConfiguration", "DataFormatConfiguration");
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
// add method for auto configure
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
javaClass.addImport("org.apache.camel.CamelContextAware");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
String body = createDataFormatBody(model.getShortJavaType());
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod()
.setName(methodName)
.setPublic()
.setBody(body)
.setReturnType(model.getShortJavaType())
.addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
method.addAnnotation(Bean.class);
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
File target = new File(srcDir, fileName);
try {
InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
String header = loadText(is);
String code = sourceToString(javaClass);
code = header + code;
getLog().debug("Source code generated:\n" + code);
if (target.exists()) {
String existing = FileUtils.readFileToString(target);
if (!code.equals(existing)) {
FileUtils.write(target, code, false);
getLog().info("Updated existing file: " + target);
} else {
getLog().debug("No changes to existing file: " + target);
}
} else {
FileUtils.write(target, code);
getLog().info("Created file: " + target);
}
} catch (Exception e) {
throw new MojoFailureException("IOError with file " + target, e);
}
}