Guest User

Untitled

a guest
Dec 11th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  7. http://www.springframework.org/schema/aop
  8. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-2.5.xsd">
  11.  
  12. <context:component-scan base-package="model.testbean" />
  13. <context:component-scan base-package="model.writer" />
  14.  
  15. package model.main;
  16.  
  17. /**
  18. * Created by barora on 12/10/2017.
  19. */
  20.  
  21. import org.springframework.beans.factory.BeanFactory;
  22. import org.springframework.context.ApplicationContext;
  23. import org.springframework.context.support.ClassPathXmlApplicationContext;
  24.  
  25. import model.testbean.MySpringBeanWithDepenency;
  26.  
  27. public class Main {
  28. public static void main(String args[]){
  29. ApplicationContext context = new ClassPathXmlApplicationContext(
  30. "BeanDefinition.xml");
  31. BeanFactory factory = context;
  32. MySpringBeanWithDepenency test = (MySpringBeanWithDepenency) factory.getBean("MySpringBeanWithDepenency");
  33. test.run();
  34. }
  35. }
  36.  
  37. import org.springframework.context.annotation.ComponentScan;
  38. import org.springframework.stereotype.Component;
  39.  
  40. import model.writer.IWriter;
  41. import org.springframework.stereotype.Service;
  42.  
  43.  
  44. @Service
  45. public class MySpringBeanWithDepenency {
  46.  
  47. private IWriter writer;
  48.  
  49. @Autowired
  50. public void setWriter(IWriter writer){
  51. this.writer = writer;
  52. }
  53.  
  54. public void run(){
  55. String s = "This is my test";
  56. writer.writer(s);
  57. }
  58. }
Add Comment
Please, Sign In to add comment