Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class GenericBeanDefinitionExample {
  2.  
  3. public static void main (String[] args) {
  4. DefaultListableBeanFactory context =
  5. new DefaultListableBeanFactory();
  6.  
  7. GenericBeanDefinition gbd = new GenericBeanDefinition();
  8. gbd.setBeanClass(MyBean.class);
  9.  
  10. MutablePropertyValues mpv = new MutablePropertyValues();
  11. mpv.add("date", new Date());
  12.  
  13. //alternatively we can use:
  14. // gbd.getPropertyValues().addPropertyValue("date", new Date());
  15. gbd.setPropertyValues(mpv);
  16.  
  17. context.registerBeanDefinition("myBeanName", gbd);
  18.  
  19. MyBean bean = context.getBean(MyBean.class);
  20. bean.doSomething();
  21. }
  22. }
Add Comment
Please, Sign In to add comment