public interface MessageService {
String getMessage();
}
public class HelloWorldService implements MessageService {
@Override
public String getMessage() {
return "Hello World!";
}
}
<beans>
<bean id="helloWorldService" class="com.example.HelloWorldService" />
</beans>
public class Application {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
MessageService service = (MessageService) context.getBean("helloWorldService");
System.out.println(service.getMessage());
}
}