|
|
@ -17,6 +17,8 @@ |
|
|
|
package org.springframework.context.annotation.configuration; |
|
|
|
package org.springframework.context.annotation.configuration; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.lang.annotation.Retention; |
|
|
|
|
|
|
|
import java.lang.annotation.RetentionPolicy; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
import javax.inject.Provider; |
|
|
|
import javax.inject.Provider; |
|
|
@ -35,6 +37,7 @@ import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Scope; |
|
|
|
import org.springframework.context.annotation.Scope; |
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
import org.springframework.context.support.GenericApplicationContext; |
|
|
|
|
|
|
|
import org.springframework.core.annotation.AliasFor; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.tests.sample.beans.Colour; |
|
|
|
import org.springframework.tests.sample.beans.Colour; |
|
|
@ -119,6 +122,20 @@ public class AutowiredConfigurationTests { |
|
|
|
doTestValueInjection(context); |
|
|
|
doTestValueInjection(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testValueInjectionWithMetaAnnotation() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext context = |
|
|
|
|
|
|
|
new AnnotationConfigApplicationContext(ValueConfigWithMetaAnnotation.class); |
|
|
|
|
|
|
|
doTestValueInjection(context); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testValueInjectionWithAliasedMetaAnnotation() { |
|
|
|
|
|
|
|
AnnotationConfigApplicationContext context = |
|
|
|
|
|
|
|
new AnnotationConfigApplicationContext(ValueConfigWithAliasedMetaAnnotation.class); |
|
|
|
|
|
|
|
doTestValueInjection(context); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testValueInjectionWithProviderFields() { |
|
|
|
public void testValueInjectionWithProviderFields() { |
|
|
|
AnnotationConfigApplicationContext context = |
|
|
|
AnnotationConfigApplicationContext context = |
|
|
@ -291,6 +308,73 @@ public class AutowiredConfigurationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("#{systemProperties[myProp]}") |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
public @interface MyProp { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
|
|
@Scope("prototype") |
|
|
|
|
|
|
|
static class ValueConfigWithMetaAnnotation { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MyProp |
|
|
|
|
|
|
|
private String name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String name2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MyProp |
|
|
|
|
|
|
|
public void setName2(String name) { |
|
|
|
|
|
|
|
this.name2 = name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean @Scope("prototype") |
|
|
|
|
|
|
|
public TestBean testBean() { |
|
|
|
|
|
|
|
return new TestBean(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean @Scope("prototype") |
|
|
|
|
|
|
|
public TestBean testBean2() { |
|
|
|
|
|
|
|
return new TestBean(name2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("") |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
public @interface AliasedProp { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = Value.class) |
|
|
|
|
|
|
|
String value(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
|
|
@Scope("prototype") |
|
|
|
|
|
|
|
static class ValueConfigWithAliasedMetaAnnotation { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasedProp("#{systemProperties[myProp]}") |
|
|
|
|
|
|
|
private String name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String name2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasedProp("#{systemProperties[myProp]}") |
|
|
|
|
|
|
|
public void setName2(String name) { |
|
|
|
|
|
|
|
this.name2 = name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean @Scope("prototype") |
|
|
|
|
|
|
|
public TestBean testBean() { |
|
|
|
|
|
|
|
return new TestBean(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean @Scope("prototype") |
|
|
|
|
|
|
|
public TestBean testBean2() { |
|
|
|
|
|
|
|
return new TestBean(name2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
static class ValueConfigWithProviderFields { |
|
|
|
static class ValueConfigWithProviderFields { |
|
|
|
|
|
|
|
|
|
|
|