25
25
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
26
26
import org .springframework .beans .factory .annotation .Required ;
27
27
import org .springframework .beans .factory .annotation .RequiredAnnotationBeanPostProcessor ;
28
+ import org .springframework .beans .factory .annotation .Value ;
28
29
import org .springframework .beans .factory .config .BeanDefinition ;
29
30
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
30
31
import org .springframework .beans .factory .config .BeanPostProcessor ;
31
32
import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
33
+ import org .springframework .beans .factory .config .PropertyPlaceholderConfigurer ;
32
34
import org .springframework .beans .factory .parsing .BeanDefinitionParsingException ;
33
35
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
34
36
import org .springframework .beans .factory .support .RootBeanDefinition ;
41
43
import org .springframework .context .annotation .Scope ;
42
44
import org .springframework .context .event .ContextRefreshedEvent ;
43
45
import org .springframework .context .support .GenericApplicationContext ;
46
+ import org .springframework .core .PriorityOrdered ;
44
47
45
48
/**
46
49
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and error
@@ -133,15 +136,20 @@ public void configurationWithPrototypeScopedBeans() {
133
136
134
137
@ Test
135
138
public void configurationWithPostProcessor () {
136
- BeanFactory factory = new AnnotationConfigApplicationContext (ConfigWithPostProcessor .class );
139
+ AnnotationConfigApplicationContext factory = new AnnotationConfigApplicationContext ();
140
+ factory .register (ConfigWithPostProcessor .class );
141
+ RootBeanDefinition placeholderConfigurer = new RootBeanDefinition (PropertyPlaceholderConfigurer .class );
142
+ placeholderConfigurer .getPropertyValues ().add ("properties" , "myProp=myValue" );
143
+ factory .registerBeanDefinition ("placeholderConfigurer" , placeholderConfigurer );
144
+ factory .refresh ();
137
145
138
146
TestBean foo = factory .getBean ("foo" , TestBean .class );
139
147
ITestBean bar = factory .getBean ("bar" , ITestBean .class );
140
148
ITestBean baz = factory .getBean ("baz" , ITestBean .class );
141
149
142
- assertEquals ("foo-processed" , foo .getName ());
143
- assertEquals ("bar-processed" , bar .getName ());
144
- assertEquals ("baz-processed" , baz .getName ());
150
+ assertEquals ("foo-processed-myValue " , foo .getName ());
151
+ assertEquals ("bar-processed-myValue " , bar .getName ());
152
+ assertEquals ("baz-processed-myValue " , baz .getName ());
145
153
146
154
SpousyTestBean listener = factory .getBean ("listenerTestBean" , SpousyTestBean .class );
147
155
assertTrue (listener .refreshed );
@@ -210,10 +218,13 @@ public TestBean baz() {
210
218
211
219
static class ConfigWithPostProcessor extends ConfigWithPrototypeBean {
212
220
221
+ @ Value ("${myProp}" )
222
+ private String myProp ;
223
+
213
224
@ Bean
214
- public BeanPostProcessor beanPostProcessor () {
215
- return new BeanPostProcessor () {
216
- String nameSuffix ;
225
+ public POBPP beanPostProcessor () {
226
+ return new POBPP () {
227
+ String nameSuffix = "-processed-" + myProp ;
217
228
public void setNameSuffix (String nameSuffix ) {
218
229
this .nameSuffix = nameSuffix ;
219
230
}
@@ -226,15 +237,18 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) {
226
237
public Object postProcessAfterInitialization (Object bean , String beanName ) {
227
238
return bean ;
228
239
}
240
+ public int getOrder () {
241
+ return 0 ;
242
+ }
229
243
};
230
244
}
231
245
232
- @ Bean
246
+ // @Bean
233
247
public BeanFactoryPostProcessor beanFactoryPostProcessor () {
234
248
return new BeanFactoryPostProcessor () {
235
249
public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) {
236
250
BeanDefinition bd = beanFactory .getBeanDefinition ("beanPostProcessor" );
237
- bd .getPropertyValues ().addPropertyValue ("nameSuffix" , "-processed" );
251
+ bd .getPropertyValues ().addPropertyValue ("nameSuffix" , "-processed-" + myProp );
238
252
}
239
253
};
240
254
}
@@ -246,6 +260,10 @@ public ITestBean listenerTestBean() {
246
260
}
247
261
248
262
263
+ public interface POBPP extends BeanPostProcessor {
264
+ }
265
+
266
+
249
267
private static class SpousyTestBean extends TestBean implements ApplicationListener <ContextRefreshedEvent > {
250
268
251
269
public boolean refreshed = false ;
0 commit comments