构建RESTful Web服务
最近在windows系统又重新搭建开发环境,下载完IntelliJ IDEA 2019.3.2 后,照着教程重新梳理了一遍基础原理。原文详见官网指引(Building a RESTful Web Service ),这里记录下中间遇到了几个小白问题
Can‘t resolve symbol “String”
在编写Greeting类完后,提示String 不存在,这里是因为IDE配置的问题。
解决方法:点开菜单栏 file -> ProjectStructure ,配置java sdk
image.png
mvnw 启动失败
教程里使用 mvnw spring-boot:run 命令来启动服务,但是我这里报错了。
G:\workspace\idea\gs-rest-service\initial>mvnw spring-boot:run
Downloading https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: protocol_version
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.apache.maven.wrapper.DefaultDownloader.downloadInternal(DefaultDownloader.java:73)
at org.apache.maven.wrapper.DefaultDownloader.download(DefaultDownloader.java:60)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:64)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:121)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
首先查了下mvnw 是什么,mvnw是Maven Wrapper的缩写。因为我们安装Maven时,默认情况下,系统所有项目都会使用全局安装的这个Maven版本。但是,对于某些项目来说,它可能必须使用某个特定的Maven版本,这个时候,就可以使用Maven Wrapper,它可以负责给这个特定的项目安装指定版本的Maven,而其他项目不受影响。
简单地说,Maven Wrapper就是给一个项目提供一个独立的,指定版本的Maven给它使用。这一部分详见介绍:使用mvnw
不过这里的mvnw 是spring-demo 的一个脚本。暂时没搞懂为什么我安装了maven ,输出里还是显示还要再下载maven
解决方案 :mvn spring-boot:run ,直接使用mvn 执行
关于参数 spring-boot:run 这一参数,大致看了下文章介绍https://blog.csdn.net/qwfys200/article/details/79983170
Fatal error compiling: 无效的标记: -parameter
本来以为可以了,结果编译又报错了:
G:\workspace\idea\gs-rest-service\initial>mvn -e spring-boot:run
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.example:rest-service >----------------------
[INFO] Building rest-service 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.2.RELEASE:run (default-cli) > test-compile @ rest-service >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ rest-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ rest-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to G:\workspace\idea\gs-rest-service\initial\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.565 s
[INFO] Finished at: 2020-02-03T18:39:45+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project rest-service: Fatal error compiling: 无效的标记: -parameters -> [He
lp 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project rest-service: Fatal
error compiling
经过多方百度,是因为我的jdk 是1.7的,然而项目的pom里面要求的是1.8
然后我又重新下载了1.8jdk,懒得在卸载,就直接覆盖了,因为windows下改环境变量好麻烦,结果装完还是不行,在cmd里查看java版本号,结果:
C:\Users\dell>java -version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
这又是什么鬼,看了注册表,是1.8没错啊,后来在文章 指导下,将 JDK 1.8 安装所在路径bin文件夹中“java.exe”、“javaw.exe”、“javaws.exe”三个文件拷贝到C:\Windows\System32目录下并覆盖 解决了
这下才顺利起动了
小结
之前mac没怎么费劲,win下竟然踩了这么多坑,然而搜索也没看到别人有类似的问题,难道别人都这么顺利的么
网友评论