本文整理汇总了Java中org.springframework.context.annotation.ClassPathBeanDefinitionScanner.scan方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPathBeanDefinitionScanner.scan方法的具体用法?Java ClassPathBeanDefinitionScanner.scan怎么用?Java ClassPathBeanDefinitionScanner.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.annotation.ClassPathBeanDefinitionScanner
的用法示例。
在下文中一共展示了ClassPathBeanDefinitionScanner.scan方法的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: 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;
}
示例13: 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());
}
}
}
}
}
示例14: testClassPathBeanDefinitionScanner
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner; //导入方法依赖的package包/类
@Test
public void testClassPathBeanDefinitionScanner() {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
scanner.scan("spring.study.componentprovider.bean");
}
示例15: 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;
}