Browse Source
* 3.1.x: Demonstrate use of @Configuration as meta-annotation Prune dead code from JmsTransactionManager#doBegin Apply @Configuration BeanNameGenerator consistently Improve @Configuration bean name discovery Fix infinite recursion bug in nested @Configuration Polish static imports Minor fix in ServletResponseMethodArgumentResolver extracted ResourceUtils.useCachesIfNecessary(URLConnection) method (SP prepared for 3.1.1 release CustomSQLExceptionTranslatorRegistry/Registrar etc revised CustomSQLExceptionTranslatorRegistry/Registrar method naming use custom InputStream traversal instead of a full byte array (SPR-911 PathMatchingResourcePatternResolver preserves caching for JNLP jar con Resource "contentLength()" implementations work with OSGi bundle resou fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartzpull/42/head
41 changed files with 622 additions and 227 deletions
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context.annotation.configuration; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.beans.factory.config.BeanDefinition; |
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
||||
import org.springframework.context.annotation.AnnotationBeanNameGenerator; |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Import; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* Unit tests ensuring that configuration class bean names as expressed via @Configuration |
||||
* or @Component 'value' attributes are indeed respected, and that customization of bean |
||||
* naming through a BeanNameGenerator strategy works as expected. |
||||
* |
||||
* @author Chris Beams |
||||
* @since 3.1.1 |
||||
*/ |
||||
public class ConfigurationBeanNameTests { |
||||
|
||||
@Test |
||||
public void registerOuterConfig() { |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
||||
ctx.register(A.class); |
||||
ctx.refresh(); |
||||
assertThat(ctx.containsBean("outer"), is(true)); |
||||
assertThat(ctx.containsBean("imported"), is(true)); |
||||
assertThat(ctx.containsBean("nested"), is(true)); |
||||
assertThat(ctx.containsBean("nestedBean"), is(true)); |
||||
} |
||||
|
||||
@Test |
||||
public void registerNestedConfig() { |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
||||
ctx.register(A.B.class); |
||||
ctx.refresh(); |
||||
assertThat(ctx.containsBean("outer"), is(false)); |
||||
assertThat(ctx.containsBean("imported"), is(false)); |
||||
assertThat(ctx.containsBean("nested"), is(true)); |
||||
assertThat(ctx.containsBean("nestedBean"), is(true)); |
||||
} |
||||
|
||||
@Test |
||||
public void registerOuterConfig_withBeanNameGenerator() { |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
||||
ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() { |
||||
public String generateBeanName( |
||||
BeanDefinition definition, BeanDefinitionRegistry registry) { |
||||
return "custom-" + super.generateBeanName(definition, registry); |
||||
} |
||||
}); |
||||
ctx.register(A.class); |
||||
ctx.refresh(); |
||||
assertThat(ctx.containsBean("custom-outer"), is(true)); |
||||
assertThat(ctx.containsBean("custom-imported"), is(true)); |
||||
assertThat(ctx.containsBean("custom-nested"), is(true)); |
||||
assertThat(ctx.containsBean("nestedBean"), is(true)); |
||||
} |
||||
|
||||
@Configuration("outer") |
||||
@Import(C.class) |
||||
static class A { |
||||
@Component("nested") |
||||
static class B { |
||||
@Bean public String nestedBean() { return ""; } |
||||
} |
||||
} |
||||
|
||||
@Configuration("imported") |
||||
static class C { |
||||
@Bean public String s() { return "s"; } |
||||
} |
||||
} |
||||
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context.annotation.configuration; |
||||
|
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import test.beans.TestBean; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* Ensures that @Configuration is supported properly as a meta-annotation. |
||||
* |
||||
* @author Chris Beams |
||||
*/ |
||||
public class ConfigurationMetaAnnotationTests { |
||||
|
||||
@Test |
||||
public void customConfigurationStereotype() { |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
||||
ctx.register(Config.class); |
||||
ctx.refresh(); |
||||
assertThat(ctx.containsBean("customName"), is(true)); |
||||
TestBean a = ctx.getBean("a", TestBean.class); |
||||
TestBean b = ctx.getBean("b", TestBean.class); |
||||
assertThat(b, sameInstance(a.getSpouse())); |
||||
} |
||||
|
||||
|
||||
@TestConfiguration("customName") |
||||
static class Config { |
||||
@Bean |
||||
public TestBean a() { |
||||
TestBean a = new TestBean(); |
||||
a.setSpouse(b()); |
||||
return a; |
||||
} |
||||
|
||||
@Bean |
||||
public TestBean b() { |
||||
return new TestBean(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface TestConfiguration { |
||||
String value() default ""; |
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context.annotation.configuration.spr8955; |
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* @author Chris Beams |
||||
* @author Willem Dekker |
||||
*/ |
||||
abstract class Spr8955Parent { |
||||
|
||||
@Component |
||||
static class Spr8955Child extends Spr8955Parent { |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.context.annotation.configuration.spr8955; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
||||
|
||||
|
||||
/** |
||||
* @author Chris Beams |
||||
* @author Willem Dekker |
||||
*/ |
||||
public class Spr8955Tests { |
||||
|
||||
@Test |
||||
public void repro() { |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
||||
ctx.scan("org.springframework.context.annotation.configuration.spr8955"); |
||||
ctx.refresh(); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue