Spring Hello World Example - Stand Alone

Maybe the simplest Spring Example?

Careful with the packages!!!
package biz.tugay.springStandAlone.service;
/* User: koray@tugay.biz Date: 08/07/15 Time: 14:07 */
 
import org.springframework.stereotype.Component;
 
@Component
public class MyServiceOne {
}
 
package biz.tugay.springStandAlone.service;
/* User: koray@tugay.biz Date: 08/07/15 Time: 14:15 */
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class MyServiceTwo {
 
    private MyServiceOne myServiceOne;
 
    @Autowired
    public void setMyServiceOne(MyServiceOne myServiceOne) {
        this.myServiceOne = myServiceOne;
    }
 
    public MyServiceOne getMyServiceOne() {
        return myServiceOne;
    }
}
 
package biz.tugay.springStandAlone.config;
/* User: koray@tugay.biz Date: 08/07/15 Time: 14:01 */
 
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
 
@Configuration
@ComponentScan(basePackages = "biz.tugay.springStandAlone.service",
        excludeFilters = @ComponentScan.Filter(Configuration.class))
public class BeanConfig {
}
 
package biz.tugay.springStandAlone;
/* User: koray@tugay.biz Date: 08/07/15 Time: 14:04 */
 
import biz.tugay.springStandAlone.config.BeanConfig;
import biz.tugay.springStandAlone.service.MyServiceOne;
import biz.tugay.springStandAlone.service.MyServiceTwo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
public class MainClass {
 
    public static void main(String[] args) {
        // Bootstrap Spring Application Context:
        ApplicationContext applicationContext
                = new AnnotationConfigApplicationContext(BeanConfig.class);
 
        MyServiceOne myServiceOne = (MyServiceOne) applicationContext.getBean("myServiceOne");
        MyServiceTwo myServiceTwo = (MyServiceTwo) applicationContext.getBean("myServiceTwo");
 
        if (myServiceTwo.getMyServiceOne() == myServiceOne)
            System.out.println("Yes, they are the same object!! Not just equal, same..");
 
        System.out.println("\nPrinting Bean Definition Names:");
        for (String beanDefinitionName : applicationContext.getBeanDefinitionNames())
            System.out.println(beanDefinitionName);
    }
}

In Action!

Output will be:
Yes, they are the same object!! Not just equal, same..
Printing Bean Definition Names:
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
beanConfig
org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
myServiceOne
myServiceTwo