當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassPathBeanDefinitionScanner類代碼示例

本文整理匯總了Java中org.springframework.context.annotation.ClassPathBeanDefinitionScanner的典型用法代碼示例。如果您正苦於以下問題:Java ClassPathBeanDefinitionScanner類的具體用法?Java ClassPathBeanDefinitionScanner怎麽用?Java ClassPathBeanDefinitionScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassPathBeanDefinitionScanner類屬於org.springframework.context.annotation包,在下文中一共展示了ClassPathBeanDefinitionScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: beanFactoryPostProcessor

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext applicationContext) {
    return new BeanFactoryPostProcessor() {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            if (beanFactory instanceof BeanDefinitionRegistry) {
                try {
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
                    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry);
                    scanner.setResourceLoader(applicationContext);
                    scanner.scan("com.quancheng.saluki.boot.web");
                } catch (Throwable e) {
                    log.error(e.getMessage(), e);
                }
            }

        }

    };
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:22,代碼來源:MonitorAutoconfiguration.java

示例2: createContext

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) {
	GenericWebApplicationContext context = new GenericWebApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	scanner.setBeanNameGenerator(new BeanNameGenerator() {
		@Override
		public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
			return definition.getScope();
		}
	});
	scanner.setScopedProxyMode(scopedProxyMode);

	// Scan twice in order to find errors in the bean definition compatibility check.
	scanner.scan(getClass().getPackage().getName());
	scanner.scan(getClass().getPackage().getName());

	context.refresh();
	return context;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ClassPathBeanDefinitionScannerScopeIntegrationTests.java

示例3: postProcessBeanFactory

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
/**
* Scan{@link com.github.ibole.microservice.config.annotation.Reference} Annotation.
*/ 
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {
  if (StringUtils.isEmpty(annotationPackage)) {
    return;
  }
  if (beanFactory instanceof BeanDefinitionRegistry) {
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;
    ClassPathBeanDefinitionScanner scanner =
        new ClassPathBeanDefinitionScanner(beanDefinitionRegistry, true);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(Reference.class);
    scanner.addIncludeFilter(filter);
    scanner.scan(annotationPackages);
  }

}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:20,代碼來源:RpcAnnotation.java

示例4: BootShim

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
public BootShim(String[] args, ConfigurableApplicationContext context) {
	this.ctx = context;

	try {
		commandLine = SimpleShellCommandLineOptions.parseCommandLine(args);
	} catch (IOException var5) {
		throw new ShellException(var5.getMessage(), var5);
	}

	this.configureApplicationContext(this.ctx);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) this.ctx);
	if (commandLine.getDisableInternalCommands()) {
		scanner.scan(new String[] { "org.springframework.shell.converters", "org.springframework.shell.plugin.support" });
	} else {
		scanner.scan(new String[] { "org.springframework.shell.commands", "org.springframework.shell.converters",
				"org.springframework.shell.plugin.support" });
	}

}
 
開發者ID:spring-projects,項目名稱:spring-data-dev-tools,代碼行數:20,代碼來源:BootShim.java

示例5: BootShim

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
public BootShim(String[] args, ConfigurableApplicationContext context) {
    this.ctx = context;

    try {
        commandLine = SimpleShellCommandLineOptions.parseCommandLine(args);
    } catch (IOException var5) {
        throw new ShellException(var5.getMessage(), var5);
    }

    this.configureApplicationContext(this.ctx);
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) this.ctx);
    if(commandLine.getDisableInternalCommands()) {
        scanner.scan(new String[]{"org.springframework.shell.converters", "org.springframework.shell.plugin.support"});
    } else {
        scanner.scan(new String[]{"org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support"});
    }

}
 
開發者ID:jeffellin,項目名稱:springshellwithboot,代碼行數:19,代碼來源:BootShim.java

示例6: registerBeanDefinitions

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    // Create the annotation-based context
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
    scanner.addIncludeFilter(new ServiceTypeFilter());
    final String basePackage = StringUtils.substringBeforeLast(importingClassMetadata.getClassName(), ".");
    scanner.scan(basePackage);
    // Import scanned services in current registry
    final String[] names = context.getBeanDefinitionNames();
    for (String name : names) {
        final BeanDefinition definition = context.getBeanDefinition(name);
        registry.registerBeanDefinition(name, definition);
    }

}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:17,代碼來源:ServiceRegistrar.java

示例7: BootShim

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
public BootShim(String[] args, ConfigurableApplicationContext context) {
    this.ctx = context;
    try {
        commandLine = SimpleShellCommandLineOptions.parseCommandLine(args);
    } catch (IOException var5) {
        throw new ShellException(var5.getMessage(), var5);
    }
    this.configureApplicationContext(this.ctx);
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) this.ctx);
    if (commandLine.getDisableInternalCommands()) {
        scanner.scan("org.springframework.shell.converters", "org.springframework.shell.plugin.support");
    } else {
        scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support");
    }
}
 
開發者ID:avast,項目名稱:hdfs-shell,代碼行數:16,代碼來源:BootShim.java

示例8: postProcessBeanFactory

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException {
	// TODO Auto-generated method stub
	TypeFilter filter = new AnnotationTypeFilter(Wmz7year.class);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) arg0,
			false);
	scanner.addIncludeFilter(filter);
	int scan = scanner.scan("com.wmz7year.main");
	System.out.println("scan:" + scan);
}
 
開發者ID:wmz7year,項目名稱:wmz7year-rpc-framework,代碼行數:11,代碼來源:Wmz7yearBeanPostProcessor.java

示例9: genericWAC

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
/**
 * Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely.
 */
@Test
public void genericWAC() {
	GenericWebApplicationContext ctx = new GenericWebApplicationContext();
	ContextLoaderListener cll = new ContextLoaderListener(ctx);

	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("bogus.pkg");

	cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:Spr8510Tests.java

示例10: createContext

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
private ApplicationContext createContext(final ScopedProxyMode scopedProxyMode) {
	GenericWebApplicationContext context = new GenericWebApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.setIncludeAnnotationConfig(false);
	scanner.setScopeMetadataResolver(new ScopeMetadataResolver() {
		@Override
		public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
			ScopeMetadata metadata = new ScopeMetadata();
			if (definition instanceof AnnotatedBeanDefinition) {
				AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
				for (String type : annDef.getMetadata().getAnnotationTypes()) {
					if (type.equals(javax.inject.Singleton.class.getName())) {
						metadata.setScopeName(BeanDefinition.SCOPE_SINGLETON);
						break;
					}
					else if (annDef.getMetadata().getMetaAnnotationTypes(type).contains(javax.inject.Scope.class.getName())) {
						metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase());
						metadata.setScopedProxyMode(scopedProxyMode);
						break;
					}
					else if (type.startsWith("javax.inject")) {
						metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
					}
				}
			}
			return metadata;
		}
	});

	// Scan twice in order to find errors in the bean definition compatibility check.
	scanner.scan(getClass().getPackage().getName());
	scanner.scan(getClass().getPackage().getName());

	context.registerAlias("classPathBeanDefinitionScannerJsr330ScopeIntegrationTests.SessionScopedTestBean", "session");
	context.refresh();
	return context;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:38,代碼來源:ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java

示例11: GenericApplicationContext

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
	// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
	GenericApplicationContext ctx = new GenericApplicationContext();
	ctx.setEnvironment(prodEnv);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
	scanner.scan("org.springframework.core.env.scan1");
	ctx.refresh();
	assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
	assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:EnvironmentSystemIntegrationTests.java

示例12: BeanDefinitionLoader

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
/**
 * Create a new {@link BeanDefinitionLoader} that will load beans into the specified
 * {@link BeanDefinitionRegistry}.
 * @param registry the bean definition registry that will contain the loaded beans
 * @param sources the bean sources
 */
BeanDefinitionLoader(BeanDefinitionRegistry registry, Object... sources) {
	Assert.notNull(registry, "Registry must not be null");
	Assert.notEmpty(sources, "Sources must not be empty");
	this.sources = sources;
	this.annotatedReader = new AnnotatedBeanDefinitionReader(registry);
	this.xmlReader = new XmlBeanDefinitionReader(registry);
	if (isGroovyPresent()) {
		this.groovyReader = new GroovyBeanDefinitionReader(registry);
	}
	this.scanner = new ClassPathBeanDefinitionScanner(registry);
	this.scanner.addExcludeFilter(new ClassExcludeFilter(sources));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:19,代碼來源:BeanDefinitionLoader.java

示例13: addService

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
/**
 * This will add a given service class to the running instance with given base path.
 *
 * @param configurableApplicationContext ConfigurableApplicationContext of running app
 * @param serviceClass                   Service class
 * @param basePath                       Base path to which the service get registered
 */
public SpringMicroservicesRunner addService(ConfigurableApplicationContext configurableApplicationContext,
                                            Class<?> serviceClass, String basePath) {
    ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner =
            new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) configurableApplicationContext);
    classPathBeanDefinitionScanner.scan(serviceClass.getPackage().getName());
    SpringMicroservicesRunner springMicroservicesRunner =
            configurableApplicationContext.getBean(SpringMicroservicesRunner.class);
    springMicroservicesRunner.deploy(basePath, configurableApplicationContext.getBean(serviceClass));
    return springMicroservicesRunner;
}
 
開發者ID:wso2,項目名稱:msf4j,代碼行數:18,代碼來源:MSF4JSpringApplication.java

示例14: scanAppRepository

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
private void scanAppRepository(AbstractApplicationContext context, Component component) {
    String appRepository = component.getManifestAttribute(APP_REPOSITORY);
    if (StringUtils.isEmpty(appRepository)) {
        return;
    }
    int count;
    if (context instanceof AnnotationConfigRegistry) {
        int before = context.getBeanDefinitionCount();
        ((AnnotationConfigRegistry) context).scan(StringUtils.split(appRepository, CONFIG_LOCATION_DELIMITERS));
        count = context.getBeanDefinitionCount() - before;
    } else {
        ClassPathBeanDefinitionScanner scanner =
                new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) context);
        scanner.setEnvironment(context.getEnvironment());
        scanner.setResourceLoader(context);
        scanner.setIncludeAnnotationConfig(false);
        count = scanner.scan(StringUtils.split(appRepository, CONFIG_LOCATION_DELIMITERS));
    }
    if (count > 0 && logger.isDebugEnabled()) {
        logger.debug("Scanned {} beans in {}", count, component.getDisplayName());
        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            BeanDefinition definition = ((GenericApplicationContext) context).getBeanDefinition(name);
            if (definition instanceof ScannedGenericBeanDefinition) {
                ScannedGenericBeanDefinition sgbd = (ScannedGenericBeanDefinition) definition;
                Class<?> beanClass;
                try {
                    beanClass = sgbd.resolveBeanClass(context.getClassLoader());
                } catch (ClassNotFoundException e) {
                    continue;
                }
                if (beanClass != null) {
                    logger.debug("\t{}", beanClass.getName());
                }
            }
        }
    }

}
 
開發者ID:Kadvin,項目名稱:spring-component-framework,代碼行數:40,代碼來源:ApplicationFeatureResolver.java

示例15: XmlBeanDefinationScannerAgent

import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //導入依賴的package包/類
private XmlBeanDefinationScannerAgent(BeanDefinitionReader reader) {
    this.reader = reader;

    if (SpringPlugin.basePackagePrefixes != null && !basePackageInited) {
        ClassPathBeanDefinitionScannerAgent xmlBeanDefinitionScannerAgent = ClassPathBeanDefinitionScannerAgent.getInstance(new ClassPathBeanDefinitionScanner(reader.getRegistry()));
        for (String basePackage : SpringPlugin.basePackagePrefixes) {
            xmlBeanDefinitionScannerAgent.registerBasePackage(basePackage);
        }
        basePackageInited = true;
    }
}
 
開發者ID:HotswapProjects,項目名稱:HotswapAgent,代碼行數:12,代碼來源:XmlBeanDefinationScannerAgent.java


注:本文中的org.springframework.context.annotation.ClassPathBeanDefinitionScanner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。