Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-2.5.xsd">
- <context:component-scan base-package="model.testbean" />
- <context:component-scan base-package="model.writer" />
- package model.main;
- /**
- * Created by barora on 12/10/2017.
- */
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import model.testbean.MySpringBeanWithDepenency;
- public class Main {
- public static void main(String args[]){
- ApplicationContext context = new ClassPathXmlApplicationContext(
- "BeanDefinition.xml");
- BeanFactory factory = context;
- MySpringBeanWithDepenency test = (MySpringBeanWithDepenency) factory.getBean("MySpringBeanWithDepenency");
- test.run();
- }
- }
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.stereotype.Component;
- import model.writer.IWriter;
- import org.springframework.stereotype.Service;
- @Service
- public class MySpringBeanWithDepenency {
- private IWriter writer;
- @Autowired
- public void setWriter(IWriter writer){
- this.writer = writer;
- }
- public void run(){
- String s = "This is my test";
- writer.writer(s);
- }
- }
Add Comment
Please, Sign In to add comment