本文整理汇总了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);
}
}
}
};
}
示例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);
}
}
示例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" });
}
}
示例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"});
}
}
示例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);
}
}
示例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");
}
}
示例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);
}
示例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()));
}
示例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));
}
示例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;
}
示例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());
}
}
}
}
}
示例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;
}
}