spring学习(1):初始项目
生活随笔
收集整理的這篇文章主要介紹了
spring学习(1):初始项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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>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?
總結
以上是生活随笔為你收集整理的spring学习(1):初始项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【排序】算法(python实现)
- 下一篇: 第七十九期:阿里程序员感慨:码农们过去暴