本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.scan()
方法的一些代码示例,展示了AnnotationConfigApplicationContext.scan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.scan()
方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:scan
[英]Perform a scan within the specified base packages.
Note that #refresh() must be called in order for the context to fully process the new classes.
[中]在指定的基本包内执行扫描。
请注意,必须调用#refresh(),以便上下文完全处理新类。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new AnnotationConfigApplicationContext, scanning for bean definitions
* in the given packages and automatically refreshing the context.
* @param basePackages the packages to check for annotated classes
*/
public AnnotationConfigApplicationContext(String... basePackages) {
this();
scan(basePackages);
refresh();
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new AnnotationConfigApplicationContext, scanning for bean definitions
* in the given packages and automatically refreshing the context.
* @param basePackages the packages to check for annotated classes
*/
public AnnotationConfigApplicationContext(String... basePackages) {
this();
scan(basePackages);
refresh();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void shouldNotScanTwice() {
TestImport.scanned = false;
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.scan(TestImport.class.getPackage().getName());
context.refresh();
context.getBean(TestConfiguration.class);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void componentScanViaImportUsingScan() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.springframework.context.annotation.componentscan.importing");
ctx.refresh();
ctx.getBean(SimpleComponent.class);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void repro() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.springframework.context.annotation.configuration.spr8955");
ctx.refresh();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Prior to the fix for SPR-8761, this test threw because the nested MyComponent
* annotation was being falsely considered as a 'lite' Configuration class candidate.
*/
@Test
public void repro() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan(getClass().getPackage().getName());
ctx.refresh();
assertThat(ctx.containsBean("withNestedAnnotation"), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Prior to fixing SPR-10546 this might have succeeded depending on the ordering the
* classes were picked up. If they are picked up in the same order as
* {@link #enclosingConfigFirstParentDefinesBean()} then it would fail. This test is
* mostly for illustration purposes, but doesn't hurt to continue using it.
*
* <p>We purposely use the {@link AEnclosingConfig} to make it alphabetically prior to the
* {@link AEnclosingConfig.ChildConfig} which encourages this to occur with the
* classpath scanning implementation being used by the author of this test.
*/
@Test
public void enclosingConfigFirstParentDefinesBeanWithScanning() {
AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext();
context = ctx;
ctx.scan(AEnclosingConfig.class.getPackage().getName());
ctx.refresh();
assertThat(context.getBean("myBean",String.class), equalTo("myBean"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void controlScan() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan(example.scannable._package.class.getPackage().getName());
ctx.refresh();
assertThat("control scan for example.scannable package failed to register FooServiceImpl bean",
ctx.containsBean("fooServiceImpl"), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void scanAndRefresh() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.scan("org.springframework.context.annotation6");
context.refresh();
context.getBean(uncapitalize(ConfigForScanning.class.getSimpleName()));
context.getBean("testBean"); // contributed by ConfigForScanning
context.getBean(uncapitalize(ComponentForScanning.class.getSimpleName()));
context.getBean(uncapitalize(Jsr330NamedForScanning.class.getSimpleName()));
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
assertEquals(1, beans.size());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void viaComponentScanning() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.springframework.context.annotation.role");
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
}
代码示例来源:origin: javahongxi/whatsmars
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class, JustConfig.class);
ctx.scan("org.hongxi.whatsmars.spring.context.annotation.repository");
ctx.refresh();
Mars mars = ctx.getBean(Mars.class);
System.out.println(mars.getCnName());
Earth earth = ctx.getBean(Earth.class);
System.out.println(earth.getCnName());
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Create a new AnnotationConfigApplicationContext, scanning for bean definitions
* in the given packages and automatically refreshing the context.
* @param basePackages the packages to check for annotated classes
*/
public AnnotationConfigApplicationContext(String... basePackages) {
this();
scan(basePackages);
refresh();
}
代码示例来源:origin: com.hotels/circus-train-core
@Override
public void initialize(AnnotationConfigApplicationContext context) {
Set<String> packageNames = provider.getPackageNames(context.getEnvironment());
if (packageNames.size() > 0) {
LOG.info("Adding packageNames '{}' to component scan.", packageNames);
context.scan(packageNames.toArray(new String[packageNames.size()]));
}
}
}
代码示例来源:origin: HotelsDotCom/circus-train
@Override
public void initialize(AnnotationConfigApplicationContext context) {
Set<String> packageNames = provider.getPackageNames(context.getEnvironment());
if (packageNames.size() > 0) {
LOG.info("Adding packageNames '{}' to component scan.", packageNames);
context.scan(packageNames.toArray(new String[packageNames.size()]));
}
}
}
代码示例来源:origin: geowarin/hibernate-examples
public static void main(String[] args) {
try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
ctx.scan(CONFIG_PACKAGE);
ctx.refresh();
MainBean bean = ctx.getBean(MainBean.class);
bean.start();
}
}
}
代码示例来源:origin: JVerstry/Web-Related-Examples
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("com.jverstry");
ctx.refresh();
MyServices mcs = ctx.getBean(MyServices.class);
System.out.println("Data: " + mcs.getMyService().getData());
}
代码示例来源:origin: wso2/msf4j
private void scanIfAnnotationConfigApplicationContext(ConfigurableApplicationContext context) {
if (context instanceof AnnotationConfigApplicationContext) {
String packagesForScan = getPackagesForScan();
((AnnotationConfigApplicationContext) context).register(MSF4JSpringConfiguration.class);
((AnnotationConfigApplicationContext) context).scan(packagesForScan);
}
}
代码示例来源:origin: org.tiogasolutions.push/tioga-push-test
@BeforeClass
public void beforeClassAutowireTest() throws Exception {
AnnotationConfigApplicationContext applicationContext;
applicationContext = new AnnotationConfigApplicationContext();
applicationContext.getEnvironment().setActiveProfiles("test");
applicationContext.scan("org.tiogasolutions.push");
applicationContext.refresh();
// Inject our unit test with any beans.
applicationContext.getBeanFactory().autowireBean(this);
}
}
代码示例来源:origin: org.tiogasolutions.jobs/tioga-jobs-test
@BeforeClass
public void beforeClassAutowireTest() throws Exception {
AnnotationConfigApplicationContext applicationContext;
applicationContext = new AnnotationConfigApplicationContext();
applicationContext.getEnvironment().setActiveProfiles("test");
applicationContext.scan("org.tiogasolutions.jobs");
applicationContext.refresh();
// Inject our unit test with any beans.
applicationContext.getBeanFactory().autowireBean(this);
}
}
代码示例来源:origin: org.tiogasolutions.notify/tioga-notify-test
@BeforeClass
public void beforeClassAutowireTest() throws Exception {
AnnotationConfigApplicationContext applicationContext;
applicationContext = new AnnotationConfigApplicationContext();
applicationContext.getEnvironment().setActiveProfiles("test");
applicationContext.scan("org.tiogasolutions.notify");
applicationContext.refresh();
// Inject our unit test with any beans.
applicationContext.getBeanFactory().autowireBean(this);
}
}
内容来源于网络,如有侵权,请联系作者删除!