1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring;
12
13 import org.mule.api.MuleContext;
14 import org.mule.api.context.MuleContextAware;
15
16 import org.springframework.beans.BeansException;
17 import org.springframework.beans.factory.config.BeanPostProcessor;
18
19
20
21
22
23
24
25
26
27 public class MuleContextPostProcessor implements BeanPostProcessor
28 {
29 private MuleContext muleContext;
30
31 public MuleContextPostProcessor(MuleContext muleContext)
32 {
33 this.muleContext = muleContext;
34 }
35
36 @Override
37 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
38 {
39 if (bean instanceof MuleContextAware)
40 {
41 if (muleContext == null)
42 {
43 return bean;
44 }
45
46 ((MuleContextAware) bean).setMuleContext(muleContext);
47 }
48 return bean;
49 }
50
51 @Override
52 public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
53 {
54 return bean;
55 }
56 }