Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. @Component
  2. public class SpringContext implements ApplicationContextAware {
  3.     private static ApplicationContext context;
  4.  
  5.     @Autowired
  6.     public void setApplicationContext(ApplicationContext context) throws BeansException {
  7.         this.context = context;
  8.     }
  9.  
  10.     public static void autowireBean(Object bean){
  11.         AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
  12.         bpp.setBeanFactory(context.getAutowireCapableBeanFactory());
  13.         bpp.processInjection(bean);
  14.     }
  15. }
  16.  
  17. public abstract class AggregateRoot {
  18.     {
  19.         SpringContext.autowireBean(this);
  20.     }
  21. }
  22.  
  23. class MyAggregate extends AggregateRoot {
  24.  
  25.     @Autowired
  26.     private MyComp myComp;
  27.  
  28.     public MyAggregate(String test, String testToo) {
  29.         this.test = test;
  30.         this.testToo = testToo;
  31.     }
  32.  
  33.     private String test;
  34.     private String testToo;
  35.  
  36.     public String getTest() {
  37.         return test;
  38.     }
  39.  
  40.     public String getTestToo() {
  41.         return testToo;
  42.     }
  43.  
  44.     public String getOk(){
  45.         return myComp.ok;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement