博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Framework tutorial
阅读量:4315 次
发布时间:2019-06-06

本文共 1385 字,大约阅读时间需要 4 分钟。


pom.xml <packaging> <artifactId>

<dependencies>

compile package install


 

<artifactId>spring-context</artifactId>

1 package hello;2 3 public interface MessageService {4     String getMessage();5 }
1 package hello; 2  3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.stereotype.Component; 5  6 @Component 7 public class MessagePrinter { 8  9     final private MessageService service;10 11     @Autowired12     public MessagePrinter(MessageService service) {13         this.service = service;14     }15 16     public void printMessage() {17         System.out.println(this.service.getMessage());18     }19 }

 

1 package hello; 2  3 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.annotation.*; 5  6 @Configuration 7 @ComponentScan 8 public class Application { 9 10     @Bean11     MessageService mockMessageService() {12         return new MessageService() {13             public String getMessage() {14               return "Hello World!";15             }16         };17     }18 19   public static void main(String[] args) {20       ApplicationContext context = 21           new AnnotationConfigApplicationContext(Application.class);22       MessagePrinter printer = context.getBean(MessagePrinter.class);23       printer.printMessage();24   }25 }

 

转载于:https://www.cnblogs.com/JosephLiao/p/4485791.html

你可能感兴趣的文章
Maven使用心得
查看>>
新浪OAuth授权
查看>>
Entity Framework之 增删改查
查看>>
把OnDraw和OnPaint弄清楚(转贴)
查看>>
jmeter java请求
查看>>
Spark- SparkStreaming可更新状态的实例
查看>>
第9月第13天 传递lua匿名函数到c/c++
查看>>
SpringMVC FormTag resolve action
查看>>
用U盘安装Linux图解
查看>>
webpack版本升级问题
查看>>
第三天实习报告
查看>>
作业 2.6
查看>>
《JavaScript DOM 编程艺术》 学习笔记
查看>>
文本控件
查看>>
元组的特性
查看>>
C#事件的基本使用
查看>>
ssh中需要增加IntrospectorCleanupListener监听器
查看>>
duilib写个三国杀?
查看>>
GateWay程序分析02_IAP_FLASH.H
查看>>
Stone Crusher Used in High-speed Railway Construction
查看>>