about URL and URI

http://java.sun.com/javaone/sf/2007...es/puzzlers.jsp

The second puzzle, aptly titled "More Joys of Sets" has the user create HashMap keys that consist or several URL objects. Again, most of the audience was unable to guess the correct answer.

The important thing the audience learned here is that the URL object's equals() method is, in effect, broken. In this case, two URL objects are equal if they resolve to the same IP address and port, not just if they have equal strings. However, Bloch and Pugh point out an even more severe Achilles' Heel: the equality behavior differs depending on if you're connected to the network, where virtual addresses can resolve to the same host, or if you're not on the net, where the resolve is a blocking operation. So, as far as lessons learned, they recommend:

* Don't use URL; use URI instead. URI makes no attempt to compare addresses or ports. In addition, don't use URL as a Set element or a Map key.
* For API designers, the equals() method should not depend on the environment. For example, in this case, equality should not change if a computer is connected to the Internet versus standalone.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25966/viewspace-53308/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25966/viewspace-53308/

S D:\project_vscode\demo> ./mvnw spring-boot:run [INFO] Scanning for projects... Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/与%20Spring%20Boot%20版本一致/spring-boot-maven-plugin-与%20Spring%20Boot%20版本一致.pom [WARNING] Failed to retrieve plugin descriptor for org.springframework.boot:spring-boot-maven-plugin:与 Spring Boot 版本一致: Plugin org.springframework.boot:spring-boot-maven-plugin:与 Spring Boot 版本一致 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 (absent): Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 from/to central (https://repo.maven.apache.org/maven2): status code: 400, reason phrase: Invalid URI (400) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.519 s [INFO] Finished at: 2025-03-21T23:58:44+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.springframework.boot:spring-boot-maven-plugin:与 Spring Boot 版本一致 or one of its dependencies could not be resolved: [ERROR] The following artifacts could not be resolved: org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 (absent): org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 failed to transfer from https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 from/to central (https://repo.maven.apache.org/maven2): status code: 400, reason phrase: Invalid URI (400) [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/PluginResolutionException
03-22
<think>嗯,用户遇到了构建失败的问题,错误信息是关于Maven插件无法解析。首先,我需要仔细看看错误日志。用户执行的是./mvnw spring-boot:run,结果提示无法下载spring-boot-maven-plugin,版本显示的是“与 Spring Boot 版本一致”,这看起来有问题。 可能用户的项目中的pom.xml文件里,插件的版本号被错误地设置成了“与 Spring Boot 版本一致”这样的占位符,而不是具体的版本号,比如3.1.5。Maven在解析时,会把这个字符串作为版本号去仓库查找,自然找不到对应的插件,导致HTTP 400错误,因为URL不合法。 接下来,我需要确认用户在pom.xml中的配置是否正确。通常,Spring Boot的父项目会管理插件版本,所以可能用户没有正确继承父项目,或者手动指定了错误的插件版本。需要检查<parent>部分是否正确,以及<plugins>中的spring-boot-maven-plugin是否指定了版本,或者是否有变量未被替换。 另外,用户可能使用了某个教程或模板,但未正确替换占位符,导致版本号保持原样。这时候需要指导用户打开pom.xml,找到插件配置部分,将版本号改为实际版本,或者引用正确的属性变量,比如${spring-boot.version},并确保属性已被定义。 还有可能是Maven本地仓库缓存的问题,但错误提示说已经缓存了失败记录,可能需要清除缓存或强制更新。不过首要问题还是版本号不正确,必须先解决版本配置问题。 总结下来,解决问题的步骤应该是:检查pom.xml中的插件版本配置,更正为正确版本号,确保父项目正确继承,然后重新运行构建命令。同时提醒用户检查项目结构,确认依赖配置无误。</think>从错误日志分析,您遇到的构建失败问题是由于Maven插件版本号配置错误导致的。以下是逐步排查和解决方案: --- ### 错误原因分析 错误日志显示: ```log Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:与 Spring Boot 版本一致 ``` - **问题定位**:`pom.xml` 文件中 `spring-boot-maven-plugin` 插件的版本号被错误地设置为字符串 `与 Spring Boot 版本一致`,而非实际版本号(如 `3.1.5`)。 - **后果**:Maven 尝试从中央仓库下载 `与 Spring Boot 版本一致` 版本的插件,但该版本号不合法,导致 HTTP 400 错误。 --- ### 解决方案 #### 步骤 1:检查 `pom.xml` 文件 找到 `spring-boot-maven-plugin` 插件的配置部分: ```xml <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>与 Spring Boot 版本一致</version> <!-- 错误配置 --> </plugin> </plugins> </build> ``` #### 步骤 2:修正插件版本号 根据您的 Spring Boot 项目实际版本,替换为具体的版本号。例如: ```xml <version>3.1.5</version> <!-- 假设实际版本是 3.1.5 --> ``` 或通过属性占位符动态获取版本号(推荐): ```xml <version>${spring-boot.version}</version> ``` 确保父项目中已定义 `spring-boot.version` 属性(通常继承自 `spring-boot-starter-parent`)。 --- #### 步骤 3:检查父项目继承 确保 `pom.xml` 中已正确继承 Spring Boot 的父项目: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.1.5</version> <!-- 与插件版本一致 --> <relativePath/> </parent> ``` --- #### 步骤 4:清理本地仓库缓存 如果之前尝试过错误构建,可能需要清理 Maven 本地仓库中的无效缓存: ```bash # 强制重新下载依赖 ./mvnw clean install -U ``` --- ### 完整修正示例 ```xml <?xml version="1.0" encoding="UTF-8"?> <project> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.1.5</version> <relativePath/> </parent> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 自动继承父项目版本号 --> </plugin> </plugins> </build> </project> ``` --- ### 附加说明 - **版本号合法性**:所有 Maven 依赖的版本号必须是合法字符串(如 `2.7.0`),不能包含中文或占位符。 - **依赖继承机制**:通过继承 `spring-boot-starter-parent`,可自动管理插件版本,无需手动指定。 修正后重新运行命令即可正常启动: ```bash ./mvnw spring-boot:run ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值