1打开idea—-new project
2点击建立项目的类型maven 点击next
3点击next
4选择路径,点击完成
5建立成功之后修改pom.xml配置文件
添加,解决依赖关系
org.springframework
spring-context
4.3.13.RELEASE
6在main下建立一个hello包—-下面建立三个类
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
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net