奇葩问题解答

2019/08/04

一、Maven相关

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

问题描述

运行命令报错: mvn clean install -DskipTests

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  23.464 s
[INFO] Finished at: 2019-08-04T11:51:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project pack-common: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :pack-common

解决方案

安装 JDK 并设置JAVA_HOME 变量;

注意:安装 JDK 后,必须要手动设置 JAVA_HOME 变量,否则依然报这个错。例如 jdk 安装在 C:\Program Files\Java\jdk1.8.0_191 JAVA_HOME

二、开发相关

spring异常:org.springframework.beans.BeanInstantiationException

问题描述

MongoRepository查询数据,数据返回组装报错

 message: "Failed to instantiate com.xxx.sync.ReceiveBasicInfoRequestVo$BasicInfo using constructor NO_CONSTRUCTOR with arguments"

cause: "org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.lxxx.sync.ReceiveBasicInfoRequestVo$BasicInfo]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.xxx.sync.ReceiveBasicInfoRequestVo$BasicInfo.<init>()",

解决方案

对象的依赖注入使用了set方法注入,如果类中只有[有参]构造方法,而没有[无参]构造方法,运行时将会出错。 原因是Spring框架的IOC实现使用了Java的反射机制,反射机制将会调用类的无参构造方法创建这个类的对象,而类中存在了[有参]的构造方法,java就不会为这个类生成[无参]构造方法,JVM映射对象时,将会出错。所以,只需要保留[无参]构造方法。


扫描关注:Andy风雨无阻

(转载本站文章请注明作者和出处 风雨无阻

Show Disqus Comments

Post Directory