经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Maven » 查看文章
导入maven项目各个注解均报错的解决方案
来源:jb51  时间:2021/12/31 8:41:17  对本文有异议

导入maven项目各个注解均报错

所遇问题

导入maven项目各个注解均报错了

思考1:

这个项目使用了springboot;spring是个”大容器”,所有对象的创建和管理都交给了它, (SpringBoot是一个框架,一种全新的编程规范,他的产生简化了框架的使用,所谓简化是指简化了Spring众多框架中所需的大量且繁琐的配置文件,所以 SpringBoot是一个服务于框架的框架,服务范围是简化配置文件。

最明显的特点是,让文件配置变的相当简单、让应用部署变的简单(SpringBoot内置服务器,并装备启动类代码),可以快速开启一个Web容器进行开发。);先去查看springboot是否扫描到这些文件;

结果:查看配置文件XML以及各层的依赖,应该没出错。

思考2:

该导入的包是否成功导入?查看maven依赖树(mvn dependency),并检查依赖版本等是否有用;结果:应该没错,依赖树上显示了加入的jar包。

思考3:

有事问度娘;百度上的方法各异;我并没有成功,也许是我操作或者对它们的理解出了问题吧;决定问大佬,我问了大佬,大佬从事安卓开发多年,所以帮我叫来另一个大佬;在另一个大佬的指点下,

解决方案

我先是去了本地仓库setting.xml下的镜像改为aliyun的镜像;(下图是查找你当前maven项目的本地仓库已经配置文件setting.xml的方法)

我这个是默认生成的,如果没有配置文件setting.xml;就自己新建一个;新建方法很多这里就不介绍了;附上我的setting.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <!--
  19. | This is the configuration file for Maven. It can be specified at two levels:
  20. |
  21. | 1. User Level. This settings.xml file provides configuration for a single
  22. | user, and is normally provided in
  23. | ${user.home}/.m2/settings.xml.
  24. |
  25. | NOTE: This location can be overridden with the CLI option:
  26. |
  27. | -s /path/to/user/settings.xml
  28. |
  29. | 2. Global Level. This settings.xml file provides configuration for all
  30. | Maven users on a machine (assuming they're all using the
  31. | same Maven installation). It's normally provided in
  32. | ${maven.home}/conf/settings.xml.
  33. |
  34. | NOTE: This location can be overridden with the CLI option:
  35. |
  36. | -gs /path/to/global/settings.xml
  37. |
  38. | The sections in this sample file are intended to give you a running start
  39. | at getting the most out of your Maven installation. Where appropriate, the
  40. | default values (values used when the setting is not specified) are provided.
  41. |
  42. |-->
  43. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  44. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  45. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  46. <!-- localRepository
  47. | The path to the local repository maven will use to store artifacts.
  48. |
  49. | Default: ~/.m2/repository
  50. <localRepository>/path/to/local/repo</localRepository>
  51. -->
  52. <!--<localRepository>C:/Users/Administrator/.m2/repository</localRepository> -->
  53. <localRepository>F:/eclipse_workspace20170314/repository</localRepository>
  54. <!-- interactiveMode
  55. | This will determine whether maven prompts you when it needs input. If set
  56. | to false, maven will use a sensible default value, perhaps based on some
  57. | other setting, for the parameter in question.
  58. |
  59. | Default: true
  60. <interactiveMode>true</interactiveMode>
  61. -->
  62. <!-- offline
  63. | Determines whether maven should attempt to connect to the network when
  64. | executing a build. This will have an effect on artifact downloads,
  65. | artifact deployment, and others.
  66. |
  67. | Default: false
  68. <offline>false</offline>
  69. -->
  70. <!-- pluginGroups
  71. | This is a list of additional group identifiers that will be searched when
  72. | resolving plugins by their prefix, i.e. when invoking a command line like
  73. | "mvn prefix:goal". Maven will automatically add the group identifiers
  74. | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not
  75. | already contained in the list.
  76. |-->
  77. <pluginGroups>
  78. <!-- pluginGroup
  79. | Specifies a further group identifier to use for plugin lookup.
  80. <pluginGroup>com.your.plugins</pluginGroup>
  81. -->
  82. </pluginGroups>
  83. <!-- proxies
  84. | This is a list of proxies which can be used on this machine to connect to
  85. | the network. Unless otherwise specified (by system property or command-
  86. | line switch), the first proxy specification in this list marked as active
  87. | will be used.
  88. |-->
  89. <proxies>
  90. <!-- proxy
  91. | Specification for one proxy, to be used in connecting to the network.
  92. |
  93. <proxy>
  94. <id>optional</id>
  95. <active>true</active>
  96. <protocol>http</protocol>
  97. <username>proxyuser</username>
  98. <password>proxypass</password>
  99. <host>proxy.host.net</host>
  100. <port>80</port>
  101. <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
  102. </proxy>
  103. -->
  104. </proxies>
  105. <!-- servers
  106. | This is a list of authentication profiles, keyed by the server-id used
  107. | within the system. Authentication profiles can be used whenever maven must
  108. | make a connection to a remote server.
  109. |-->
  110. <servers>
  111. <!-- server
  112. | Specifies the authentication information to use when connecting to a
  113. | particular server, identified by a unique name within the system
  114. | (referred to by the 'id' attribute below).
  115. |
  116. | NOTE: You should either specify username/password OR
  117. | privateKey/passphrase, since these pairings are used together.
  118. |
  119. <server>
  120. <id>deploymentRepo</id>
  121. <username>repouser</username>
  122. <password>repopwd</password>
  123. </server>
  124. -->
  125. <!-- Another sample, using keys to authenticate.
  126. <server>
  127. <id>siteServer</id>
  128. <privateKey>/path/to/private/key</privateKey>
  129. <passphrase>optional; leave empty if not used.</passphrase>
  130. </server>
  131. -->
  132. </servers>
  133. <!-- mirrors
  134. | This is a list of mirrors to be used in downloading artifacts from remote
  135. | repositories.
  136. |
  137. | It works like this: a POM may declare a repository to use in resolving
  138. | certain artifacts. However, this repository may have problems with heavy
  139. | traffic at times, so people have mirrored it to several places.
  140. |
  141. | That repository definition will have a unique id, so we can create a
  142. | mirror reference for that repository, to be used as an alternate download
  143. | site. The mirror site will be the preferred server for that repository.
  144. |-->
  145. <mirrors>
  146. <!-- mirror
  147. | Specifies a repository mirror site to use instead of a given repository.
  148. | The repository that this mirror serves has an ID that matches the
  149. | mirrorOf element of this mirror. IDs are used for inheritance and direct
  150. | lookup purposes, and must be unique across the set of mirrors.
  151. |
  152. <mirror>
  153. <id>mirrorId</id>
  154. <mirrorOf>repositoryId</mirrorOf>
  155. <name>Human Readable Name for this Mirror.</name>
  156. <url>http://my.repository.com/repo/path</url>
  157. </mirror>
  158. -->
  159. <mirror>
  160. <id>nexus-aliyun</id>
  161. <mirrorOf>*</mirrorOf>
  162. <name>Nexus aliyun</name>
  163. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  164. </mirror>
  165. <!-- profiles
  166. | This is a list of profiles which can be activated in a variety of ways,
  167. | and which can modify the build process. Profiles provided in the
  168. | settings.xml are intended to provide local machine-specific paths and
  169. | repository locations which allow the build to work in the local
  170. | environment.
  171. |
  172. | For example, if you have an integration testing plugin - like cactus -
  173. | that needs to know where your Tomcat instance is installed, you can
  174. | provide a variable here such that the variable is dereferenced during the
  175. | build process to configure the cactus plugin.
  176. |
  177. | As noted above, profiles can be activated in a variety of ways. One
  178. | way - the activeProfiles section of this document (settings.xml) - will be
  179. | discussed later. Another way essentially relies on the detection of a
  180. | system property, either matching a particular value for the property, or
  181. | merely testing its existence. Profiles can also be activated by JDK
  182. | version prefix, where a value of '1.4' might activate a profile when the
  183. | build is executed on a JDK version of '1.4.2_07'. Finally, the list of
  184. | active profiles can be specified directly from the command line.
  185. |
  186. | NOTE: For profiles defined in the settings.xml, you are restricted to
  187. | specifying only artifact repositories, plugin repositories, and
  188. | free-form properties to be used as configuration variables for
  189. | plugins in the POM.
  190. |
  191. |-->
  192. <profiles>
  193. <!-- profile
  194. | Specifies a set of introductions to the build process, to be activated
  195. | using one or more of the mechanisms described above. For inheritance
  196. | purposes, and to activate profiles via <activatedProfiles/> or the
  197. | command line, profiles have to have an ID that is unique.
  198. |
  199. | An encouraged best practice for profile identification is to use a
  200. | consistent naming convention for profiles, such as 'env-dev',
  201. | 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. This
  202. | will make it more intuitive to understand what the set of introduced
  203. | profiles is attempting to accomplish, particularly when you only have a
  204. | list of profile id's for debug.
  205. |
  206. | This profile example uses the JDK version to trigger activation, and
  207. | provides a JDK-specific repo.
  208. <profile>
  209. <id>jdk-1.4</id>
  210. <activation>
  211. <jdk>1.4</jdk>
  212. </activation>
  213. <repositories>
  214. <repository>
  215. <id>jdk14</id>
  216. <name>Repository for JDK 1.4 builds</name>
  217. <url>http://www.myhost.com/maven/jdk14</url>
  218. <layout>default</layout>
  219. <snapshotPolicy>always</snapshotPolicy>
  220. </repository>
  221. </repositories>
  222. </profile>
  223. -->
  224. <!--
  225. | Here is another profile, activated by the system property 'target-env'
  226. | with a value of 'dev', which provides a specific path to the Tomcat
  227. | instance. To use this, your plugin configuration might hypothetically
  228. | look like:
  229. |
  230. | ...
  231. | <plugin>
  232. | <groupId>org.myco.myplugins</groupId>
  233. | <artifactId>myplugin</artifactId>
  234. |
  235. | <configuration>
  236. | <tomcatLocation>${tomcatPath}</tomcatLocation>
  237. | </configuration>
  238. | </plugin>
  239. | ...
  240. |
  241. | NOTE: If you just wanted to inject this configuration whenever someone
  242. | set 'target-env' to anything, you could just leave off the
  243. | <value/> inside the activation-property.
  244. |
  245. <profile>
  246. <id>env-dev</id>
  247. <activation>
  248. <property>
  249. <name>target-env</name>
  250. <value>dev</value>
  251. </property>
  252. </activation>
  253. <properties>
  254. <tomcatPath>/path/to/tomcat/instance</tomcatPath>
  255. </properties>
  256. </profile>
  257. -->
  258. </profiles>
  259. <!-- activeProfiles
  260. | List of profiles that are active for all builds.
  261. |
  262. <activeProfiles>
  263. <activeProfile>alwaysActiveProfile</activeProfile>
  264. <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  265. </activeProfiles>
  266. -->
  267. </settings>

如何修改成aliyun镜像:

然后去本地仓库把.lastUpdated为后缀的文件删除了;再重新下载依赖;也就那些jar包,解决了吗?并没有,再试一次?去本地仓库把.lastUpdated为后缀的文件删除了,重新导入maven项目;不成啊。最后,我把本地仓库里的jar全删除了,再重新导入项目,重新下载依赖,就成功了。

原因:本地仓库里存有上一个项目所留下jar包,jar版本不同起了冲突,所以有一些jar无法使用,或者是导入项目后加载依赖时出现了jar包破损。(恳请纠正我,我也是百度并自己理解的出来的原因)

如果查看错误,出现不能被读或者它某jar也许是个zip文件这类错误,就是jdk版本太低,去更换一下项目的jdk环境,选择项目属性进行查看并更改

新导入maven项目注解爆红,所有依赖包无法导入

刚开始做maven项目时,导入网上的一个开源spring boot项目结果整体崩掉,所有注解全部报错,进行下载依赖无法下载,idea中点击无反应,搜了一下午的bug也未彻底解决:

在这里插入图片描述

经过反复测试终于发现原因所在!!!

是因为本人电脑系统所致,在配置maven环境变量是无法读取引用路径符号%,导致maven没彻底配置成功,即使cmd输入 mvn -v显示没问题

解决步骤如下

在系统变量配置中配置path变量时使用maven安装的bin目录绝对路径即可!!!

在这里插入图片描述

在这里插入图片描述

此bug可能仅是部分小伙伴的系统会出现,一定记住谨防采坑!!!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持w3xue

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号