當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。