iot前台开发环境:搭建 SpringBoot+angularJs2

参考网站

Angular 中文官网:https://angular.cn/前端

参考代码:https://ng.ant.design/#/components/dropdown java

npm install -g @angular/cli  ->  npm install -> ng build -> 普通angular工程:ng server  node

npm install -g @angular/cli  ->  npm install -> ng build -> 增长跨域配置工程启动: npm start mysql

1、安装软件

一、安装nodejs 和 angularjs/cli

          https://nodejs.org/en/angularjs

        安装 nodejs

          

        安装 angularjs/cli:   npm  install  -g   @angular/cli

        执行 npm install

 

         执行 ng build,编译前台代码输出到 spring boot 资源目录

二、安装augury

在google网上应用商店添加插件augury ,用来调试前端代码web

三、新建普通的 angular 项目 - ng new hello

经过命令 ng new hello 生成一个新项目以及应用的骨架代码redis

经过命令 ng server 启动项目,默认端口4200。 spring

2、Spring boot 和 angular 集成

Spring boot 须要修改的地方在angular-cli.json中:sql

 

一、在springboot项目中新建/复制 angular 项目

方法一: 在src 目录下经过命令添加angular项目 : ng new angularnpm

方法二: 将以前建立好的项目copy进来

设置angular项目的输出目录为springboot的资源目录

修改angular-cli.json 配置文件的name 和 outDir

该项目下name为 iot_hub

   outDir 为../resources/static(静态资源路径,系统能够直接访问且路径下的全部文件都可被直接读取)

 编译angular项目,产生输出到springboot资源目录

npm  install

ng  server --proxy-conf proxy.conf

 

  ng build

 

二、启动工程

一、启动Spring boot 

二、启动前端angular工程调试:npm  start 

三、访问服务

http://localhost:8080

http://localhost:4200

 

 

3、附录 - 常见问题

一、解决跨域问题

加一个这样的文件

 

同时修改package.json中的start

二、热部署调试工程

buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
maven {
url "http://repo.iop.inspur.com:8081/nexus/content/groups/public"
}
}

dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.inspur.iot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
maven {
url "http://repo.iop.inspur.com:8081/nexus/content/groups/public"
}
}
bootRun {
addResources = true
}

configurations.all {
exclude module: 'google-collections' 
}

dependencies {

compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')

compile('io.springfox:springfox-swagger2:2.6.1')
compile('io.springfox:springfox-swagger-ui:2.6.1')

compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('mysql:mysql-connector-java:5.1.21')

compile('org.springframework.boot:spring-boot-starter-data-redis')
// compile("org.springframework:spring-orm")

compile("org.springframework.boot:spring-boot-devtools")
compile ("org.springframework.boot:spring-boot-maven-plugin:1.5.9.RELEASE")

testCompile('org.springframework.boot:spring-boot-starter-test')}

相关文章
相关标签/搜索