用IDEA构建一个简单的微服务,用spring-boot-maven-plugin插件的run目标(goal)构建工程,报错如下:
工程的pom文件如下:
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zswang</groupId> <artifactId>license-service</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Eagle-eye Licensing Service</name> <description>Licensing Service</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.4.RELEASE</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>2.0.4.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
首先观察报错内容,主要是actuate出错:
根据横云断岭这篇分析,这个错误来自于springboot2更改类名,但是我这儿用的是springboot1啊(不信你看这个工程的pom继承的pom的版本是1.4.4.RELEASE)。后来仔细一看发现,我的spring-boot-starter-actuator用的版本是2.0.4.RELEASE。原来如此,果断改成1.4.4.RELEASE,spingboot:run成功了!