Spring Scopes in Stand Alone Application Example

Not a Web App... No no.. Just an old school stand alone app!

Yada, yada, yada here is the code:
package biz.tugay;
/* User: koray@tugay.biz Date: 25/12/15 Time: 19:36 */
 
public interface Foo {
    void foo();
}
 
package biz.tugay;
/* User: koray@tugay.biz Date: 25/12/15 Time: 19:31 */
 
import org.springframework.stereotype.Component;
 
import static java.lang.System.out;
 
@Component
public class FooImpl implements Foo {
 
    public void foo() {
        out.println("Hello World!");
    }
 
}
 
package biz.tugay;
/* User: koray@tugay.biz Date: 25/12/15 Time: 19:35 */
 
public interface Bar {
}
 
package biz.tugay;
/* User: koray@tugay.biz Date: 25/12/15 Time: 19:33 */
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
 
@Component
@Scope(value = "prototype")
public class BarImpl implements Bar {
 
    private Foo foo;
 
    void bar() {
        System.out.println("Bar!");
        foo.foo();
    }
 
    @Autowired
    public void setFoo(Foo foo) {
        this.foo = foo;
    }
}
 
package biz.tugay;
/* User: koray@tugay.biz Date: 25/12/15 Time: 19:30 */
 
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
 
@Configuration
@ComponentScan
public class SpringConfiguration {
 
}
 
package biz.tugay;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
import static java.lang.System.*;
 
public class TestClass {
    public static void main(String[] args) {
        final ApplicationContext applicationContext =
                new AnnotationConfigApplicationContext(SpringConfiguration.class);
        out.println(applicationContext.getBean(BarImpl.class));
        out.println(applicationContext.getBean(BarImpl.class));
        out.println(applicationContext.getBean(FooImpl.class));
        out.println(applicationContext.getBean(FooImpl.class));
    }
}

And the output:
biz.tugay.BarImpl@5c6d47fc
biz.tugay.BarImpl@a9120cc
biz.tugay.FooImpl@3e00367f
biz.tugay.FooImpl@3e00367f