当前位置: 首页>>代码示例>>Java>>正文


Java EnableConfigurationProperties类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:71,代码来源:SpringBootAutoConfigurationMojo.java

示例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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:72,代码来源:SpringBootAutoConfigurationMojo.java


注:本文中的org.springframework.boot.context.properties.EnableConfigurationProperties类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。