本文整理汇总了Java中org.springframework.context.annotation.ClassPathBeanDefinitionScanner类的典型用法代码示例。如果您正苦于以下问题:Java ClassPathBeanDefinitionScanner类的具体用法?Java ClassPathBeanDefinitionScanner怎么用?Java ClassPathBeanDefinitionScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassPathBeanDefinitionScanner类属于org.springframework.context.annotation包,在下文中一共展示了ClassPathBeanDefinitionScanner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: testClassPathBeanDefinitionScanner
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入依赖的package包/类
@Test
public void testClassPathBeanDefinitionScanner() {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
scanner.scan("spring.study.componentprovider.bean");
}
开发者ID:fangjian0423,项目名称:springboot-analysis,代码行数:6,代码来源:SpringEmbeddedProviderTest.java
示例17: parse
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入依赖的package包/类
public BeanDefinition parse(Element element, ParserContext parserContext)
{
ClassPathBeanDefinitionScanner scanner = new DwrClassPathBeanDefinitionScanner(parserContext.getRegistry());
String basePackage = element.getAttribute("base-package");
// Override - By default Spring uses a name generator that uses AnnotationBeanNameGenerator which uses the name specified on the Component
// annotation and if not present uses the simple name. Since our annotation-scanner doesn't scan @Component if two classes with the
// same simple name exist in different packages there will be issues. See https://directwebremoting.atlassian.net/browse/DWR-651.
scanner.setBeanNameGenerator(new DefaultBeanNameGenerator());
if (!hasText(basePackage))
{
if (log.isInfoEnabled())
{
log.info("No base package defined for classpath scanning. Traversing the whole JVM classpath");
}
}
String regex = element.getAttribute("regex");
if (hasText(regex))
{
scanner.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(regex)));
}
String proxies = element.getAttribute("scanRemoteProxy");
if (hasText(proxies) && ("TRUE".equals(proxies.toUpperCase()) || "FALSE".equals(proxies.toUpperCase())))
{
scanProxies = Boolean.parseBoolean(proxies);
}
if (scanProxies)
{
scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteProxy.class));
}
String conv = element.getAttribute("scanDataTransferObject");
if (hasText(conv) && ("TRUE".equals(conv.toUpperCase()) || "FALSE".equals(conv.toUpperCase())))
{
scanConverters = Boolean.parseBoolean(conv);
}
if (scanConverters)
{
scanner.addIncludeFilter(new AnnotationTypeFilter(DataTransferObject.class));
}
String filters = element.getAttribute("scanGlobalFilter");
if (hasText(filters) && ("TRUE".equals(filters.toUpperCase()) || "FALSE".equals(filters.toUpperCase())))
{
scanFilters = Boolean.parseBoolean(filters);
}
if (scanFilters)
{
scanner.addIncludeFilter(new AnnotationTypeFilter(GlobalFilter.class));
}
if (scanProxies | scanConverters | scanFilters)
{
scanner.scan(basePackage == null ? "" : basePackage);
}
else
{
log.warn("Scan is not required if all @RemoteProxy, @DataTransferObject and @GlobalFilter are disabled. Skipping detection");
}
return null;
}
开发者ID:directwebremoting,项目名称:dwr,代码行数:58,代码来源:AnnotationScannerParser.java
示例18: AnnotationConfigApplicationContext
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入依赖的package包/类
/**
* Create a new AnnotationConfigApplicationContext that needs to be populated
* through {@link #register} calls and then manually {@linkplain #refresh refreshed}.
*/
public AnnotationConfigApplicationContext() {
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
开发者ID:elasticsoftwarefoundation,项目名称:elasticactors,代码行数:9,代码来源:AnnotationConfigApplicationContext.java
示例19: getClassPathBeanDefinitionScanner
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入依赖的package包/类
/**
* Build a {@link ClassPathBeanDefinitionScanner} for the given bean factory.
* <p>This should be pre-configured with the {@code Environment} (if desired)
* but not with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet.
* @param beanFactory the bean factory to load bean definitions into
* @since 4.1.9
* @see #getEnvironment()
* @see #getBeanNameGenerator()
* @see #getScopeMetadataResolver()
*/
protected ClassPathBeanDefinitionScanner getClassPathBeanDefinitionScanner(DefaultListableBeanFactory beanFactory) {
return new ClassPathBeanDefinitionScanner(beanFactory, true, getEnvironment());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AnnotationConfigWebApplicationContext.java
示例20: AnnotationConfigEmbeddedWebApplicationContext
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入依赖的package包/类
/**
* Create a new {@link AnnotationConfigEmbeddedWebApplicationContext} that needs to be
* populated through {@link #register} calls and then manually {@linkplain #refresh
* refreshed}.
*/
public AnnotationConfigEmbeddedWebApplicationContext() {
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:AnnotationConfigEmbeddedWebApplicationContext.java
注:本文中的org.springframework.context.annotation.ClassPathBeanDefinitionScanner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论