Introduce AnnotationConfigWAC #scan and #register
Primarily for use in conjunction with ApplicationContextInitializer, these new #scan and #register methods mirror those in AnnotationConfigApplicationContext. #setConfigLocation and #setConfigLocations methods remain for compatibility with ContextLoader-style initialization, but have been locally overridden and documented clearly. AnnotationConfigWebApplicationContext#loadBeanDefinitions Javadoc has also been updated to explain the processing logic for each of these potential inputs. Issue: SPR-8320
This commit is contained in:
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -28,8 +28,20 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class AnnotationConfigWebApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void testSingleWellFormedConfigLocation() {
|
||||
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
|
||||
public void registerSingleClass() {
|
||||
AnnotationConfigWebApplicationContext ctx =
|
||||
new AnnotationConfigWebApplicationContext();
|
||||
ctx.register(Config.class);
|
||||
ctx.refresh();
|
||||
|
||||
TestBean bean = ctx.getBean(TestBean.class);
|
||||
assertNotNull(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configLocationWithSingleClass() {
|
||||
AnnotationConfigWebApplicationContext ctx =
|
||||
new AnnotationConfigWebApplicationContext();
|
||||
ctx.setConfigLocation(Config.class.getName());
|
||||
ctx.refresh();
|
||||
|
||||
@@ -41,7 +53,7 @@ public class AnnotationConfigWebApplicationContextTests {
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
public TestBean testBean() {
|
||||
public TestBean myTestBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user