1打开idea----new project
2点击建立项目的类型maven 点击next
3点击next
4选择路径,点击完成
5建立成功之后修改pom.xml配置文件
添加,解决依赖关系
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.13.RELEASE</version> </dependency> </dependencies>
MesasageService类 package hello; public class MesasageService { /** * 执行打印功能 * @return 返回要打印的字符串 */ public String getMessage(){ return "Hello World"; } }MessagePrinter类 package hello; public class MessagePrinter { private MesasageService service; /* * 简历和MessageService的关系 * */ //设置service的值 public void setService(MesasageService service){ this.service =service; } public void printMessage(){ System.out.println(this.service.getMessage()); } }application类 package hello; import javax.print.attribute.standard.RequestingUserName; public class Application { public static void main(String[] args){ System.out.println("application" + ""); //创建打印机对象 MessagePrinter printer = new MessagePrinter(); //创建消息服务对象 MesasageService service = new MesasageService(); //设置打印机属性 printer.setService(service); //打印消息 printer.printMessage(); } }运行结果 application Hello World