上篇文章我们讲解了使用SpringBoot整合Angular的时候的基础环境的配置,我们这篇文章主要讲解让Angular去和SpringBoot进行整合操作.
- 修改pom文件为以下内容
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.edurt</groupId>
<artifactId>springboot-angular-integration</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>springboot-angular-integration</name>
<url>http://maven.apache.org</url>
<properties>
<system.java.version>1.8</system.java.version>
<!-- node & npm -->
<system.node.version>v8.2.1</system.node.version>
<system.npm.version>5.4.2</system.npm.version>
<dependency.springboot.version>1.5.6.RELEASE</dependency.springboot.version>
<plugin.springboot.version>1.5.9.RELEASE</plugin.springboot.version>
<!-- plugin -->
<plugin.frontend.version>0.0.27</plugin.frontend.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${dependency.springboot.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${plugin.springboot.version}</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<!-- Frontend -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${plugin.frontend.version}</version>
<configuration>
<!-- angular 源码根目录 angular -->
<workingDirectory>src/main/angular</workingDirectory>
<nodeDownloadRoot>https://npm.taobao.org/mirrors/node/</nodeDownloadRoot>
<nodeVersion>${system.node.version}</nodeVersion>
<npmVersion>${system.npm.version}</npmVersion>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
<installDirectory>target</installDirectory>
</configuration>
</execution>
<execution>
<id>angular cli build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
复制代码
- 修改.angular-cli.json文件编译输出配置
"outDir": "../resources/static",
复制代码