–公司內網專案,只能貼部分程式碼,個人梳理總結
–後臺採用SpringBoot框架,前臺Angular2,打包maven docker
1.建立一個maven專案,create3個子專案,前臺專案,後臺專案,合併打包專案
–父pom
<groupId>com.xxx.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>console-backend</module>
<module>console-frontend</module>
<module>console-integrated</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
–子pom,後臺
<parent>
<groupId>com.huawei.apaas</groupId>
<artifactId>paas-operation-console</artifactId>
<version>1.0</version>
</parent>
<artifactId>console-backend</artifactId>
<properties>
<java.version>1.8</java.version>
<swagger2markup.version>1.2.0</swagger2markup.version>
</properties>
–子pom,前臺
<parent>
<groupId>com.huawei.apaas</groupId>
<artifactId>paas-operation-console</artifactId>
<version>1.0</version>
</parent>
<artifactId>console-frontend</artifactId>
<packaging>pom</packaging>
–子pom,部署,配置打包名稱,路徑,resouce來源等
<parent>
<groupId>com.huawei.apaas</groupId>
<artifactId>paas-operation-console</artifactId>
<version>1.0</version>
</parent>
<artifactId>console-integrated</artifactId>
<packaging>war</packaging>
2.後臺啟動
SpringBoot的啟動類,注意掃包路徑
resources中配置一些啟動引數,如:
schema.sql–>專案啟動自動執行的資料庫指令碼
application.yaml可配置以開發模式還是生產模式啟動,資料庫資訊,快取配置,server資訊等
paas-dev.properties可配置環境變數資訊等
application-dev.yml可配置資料庫資訊,日誌資訊等
(server: port: 8090 servlet-path: /rest –> 表示後臺以8090埠啟動,暴露/rest來代理localhost:8080;只針對開發模式,生產模式參考server.xml中配置的上下文
)
(prod模式參考dev模式)
3.前臺啟動
前臺proxy.conf.json檔案中配置代理資訊
“/rest”: {
“target”: “http://localhost:8090”,
“secure”: false
}
表示以rest代理http://localhost:8090,訪問後臺介面示例:get(‘rest/serviceinstances’),rest即代表後臺介面
前臺啟動命令:ng serve –port 4200 –host 10.134.161.60 –no-live-reload –baseHref /xxx –proxy-config proxy.conf.json
表示以4200埠啟動,baseHref /xxx表示主頁為10.134.161.60:4200/xxx,可以不加; –proxy-config….表示載入代理檔案
可在package.json中的scripts的start中配置此命令,以npm start啟動前臺專案
.angular-cli.json中配置專案啟動預載入的檔案
package.json中配置專案名稱,啟動命令,打包命令,依賴等
4.前後臺均啟動後,如何訪問後臺介面
http://10.134.161.60:4200/rest/serviceinstances
http://10.134.161.60:4200 –> 前臺啟動4200
/rest –> 後臺啟動8090
/serviceinstances –> 後臺controller中配置的mapping介面(@GetMapping(path = “/serviceinstances”))
5.合併部署
命令:mvn clean install -Pdocker -DskipTests
太難…不寫了,一堆配置檔案
写评论
很抱歉,必須登入網站才能發佈留言。