Skip to content

Commit 8e6e6c2

Browse files
committed
Test for base package specified as config location
Issue: SPR-11647
1 parent 299776f commit 8e6e6c2

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,25 +17,25 @@
1717
package org.springframework.web.context.support;
1818

1919
import org.junit.Test;
20+
2021
import org.springframework.beans.factory.config.BeanDefinition;
2122
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2223
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
2324
import org.springframework.context.annotation.Bean;
2425
import org.springframework.context.annotation.Configuration;
2526

2627
import static org.hamcrest.CoreMatchers.*;
27-
2828
import static org.junit.Assert.*;
2929

3030
/**
3131
* @author Chris Beams
32+
* @author Juergen Hoeller
3233
*/
3334
public class AnnotationConfigWebApplicationContextTests {
3435

3536
@Test
3637
public void registerSingleClass() {
37-
AnnotationConfigWebApplicationContext ctx =
38-
new AnnotationConfigWebApplicationContext();
38+
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
3939
ctx.register(Config.class);
4040
ctx.refresh();
4141

@@ -45,19 +45,27 @@ public void registerSingleClass() {
4545

4646
@Test
4747
public void configLocationWithSingleClass() {
48-
AnnotationConfigWebApplicationContext ctx =
49-
new AnnotationConfigWebApplicationContext();
48+
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
5049
ctx.setConfigLocation(Config.class.getName());
5150
ctx.refresh();
5251

5352
TestBean bean = ctx.getBean(TestBean.class);
5453
assertNotNull(bean);
5554
}
5655

56+
@Test
57+
public void configLocationWithBasePackage() {
58+
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
59+
ctx.setConfigLocation("org.springframework.web.context.support");
60+
ctx.refresh();
61+
62+
TestBean bean = ctx.getBean(TestBean.class);
63+
assertNotNull(bean);
64+
}
65+
5766
@Test
5867
public void withBeanNameGenerator() {
59-
AnnotationConfigWebApplicationContext ctx =
60-
new AnnotationConfigWebApplicationContext();
68+
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
6169
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() {
6270
@Override
6371
public String generateBeanName(BeanDefinition definition,
@@ -73,14 +81,15 @@ public String generateBeanName(BeanDefinition definition,
7381

7482
@Configuration("myConfig")
7583
static class Config {
84+
7685
@Bean
7786
public TestBean myTestBean() {
7887
return new TestBean();
7988
}
8089
}
8190

82-
static class NotConfigurationAnnotated { }
8391

84-
static class TestBean { }
92+
static class TestBean {
93+
}
8594

8695
}

0 commit comments

Comments
 (0)