This example will be used in our homework. We used the Spring32xStarterProj and copy/pasted it in the Eclipse Project Explorer to the new name: HelloSpring32xProj

Project Source: http://projects.spring.io/spring-framework/

Application.java Application

package hello;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;

@Configuration
@ComponentScan
public class Application {

    @Bean
    MessageService mockMessageService() {
        return new MessageService() {
            public String getMessage() {
              return "Hello World!";
            }
        };
    }

  public static void main(String[] args) {
      ApplicationContext context = 
          new AnnotationConfigApplicationContext(Application.class);
      MessagePrinter printer = context.getBean(MessagePrinter.class);
      printer.printMessage();
  }
}

MessageService.java Service

package hello;

public interface MessageService {
    String getMessage();
}

MessagePrinter.java View

package hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessagePrinter {

    final private MessageService service;

    @Autowired
    public MessagePrinter(MessageService service) {
        this.service = service;
    }

    public void printMessage() {
        System.out.println(this.service.getMessage());
    }
}

Eclipse™ Java Project
HelloSpring32x3Proj.zip
(Download to your downloads folder or another easily remembered folder.)