【ERROR】Error: 404 - Could not find API route. Please check your available APIs.

问题描述

这样的,我小心翼翼终于启动了dev容器后,决定不怎么动它,只在angular里面写东西。
启动angular后发现页面上有这个问题:

Error: 404 - Could not find API route. Please check your available APIs.

在这里插入图片描述
在这里插入图片描述
可我检查了3000的rest api,很正常啊!
?????
所以
?????
在这里插入图片描述

解决方法

参考这篇
https://stackoverflow.com/questions/46563282/hyperledger-rest-server-angular-web-app-getting-could-not-connect-to-rest-server
修改angular目录下proxy.cong.js的代码,start栏。

  "scripts": {
    "ng": "ng",
    "build": "ng build",
    "prepack": "npm run build",
    "start": "ng serve --proxy-config proxy.conf.js --host localhost",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test --watch false",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain/CSupplyChain$ npm start

> CSupplyChain@0.0.1 start /home/cielo/cprogrames/csupplychain/CSupplyChain
> ng serve --proxy-config proxy.conf.js --host localhost

** NG Live Development Server is running on http://localhost:4200 **
 10% building modules 4/4 modules 0 active[HPM] Proxy created: [ '/auth', '/api' ]  ->  http://localhost:3000
[HPM] Proxy created: /  ->  http://localhost:3000
Hash: 4f13260bee9704e3d77b                                                               
Time: 23629ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 297 kB {5} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 101 kB {4} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 184 kB {5} [initial] [rendered]
chunk    {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 464 kB {5} [initial] [rendered]
chunk    {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.16 MB [initial] [rendered]
chunk    {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.

配置

Composer rest server的配置如下:


cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain/dist$ composer-rest-server
? Enter the name of the business network card to use: admin@csupplychain
? Specify if you want namespaces in the generated REST API: always use namespaces
? Specify if you want to use an API key to secure the REST API: No
? Specify if you want to enable authentication for the REST API using Passport: No
? Specify if you want to enable the explorer test interface: Yes
? Specify a key if you want to enable dynamic logging: csupplychain
? Specify if you want to enable event publication over WebSockets: Yes
? Specify if you want to enable TLS security for the REST API: No

To restart the REST server using the same options, issue the following command:
   composer-rest-server -c admin@csupplychain -n always -u true -d csupplychain -w true

Discovering types from business network definition ...
Discovering the Returning Transactions..
Discovered types from business network definition
Generating schemas for all types in business network definition ...
Generated schemas for all types in business network definition
Adding schemas for all types to Loopback ...
Added schemas for all types to Loopback
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
Rest Server dynamic logging is enabled

angular的配置如下:

cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain$ yo hyperledger-composer:angular
Welcome to the Hyperledger Composer Angular project generator
? Do you want to connect to a running Business Network? Yes
? Project name: CSupplyChain
? Description: Hyperledger Composer Angular project
? Author name: cielo
? Author email: cielo0@qq.com
? License: Apache-2.0
? Name of the Business Network card: admin@csupplychain
? Do you want to generate a new REST API or connect to an existing REST API?  Connect to an existing REST API
? REST server address: http://localhost
? REST server port: 3000
? Should namespaces be used in the generated REST API? Namespaces are used
Created application!
Completed generation process
   create app.js
   create Dockerfile
   create e2e/app.e2e-spec.ts
   create e2e/app.po.ts
   create e2e/tsconfig.e2e.json
   create e2e/tsconfig.json
   create karma.conf.js
   create manifest.yml
   create package.json
   create protractor.conf.js
   create proxy.conf.js
   create README.md
   create src/app/app-routing.module.ts
   create src/app/app.component.css
   create src/app/app.component.html
   create src/app/app.component.spec.ts
   create src/app/app.component.ts
   create src/app/app.module.ts
   create src/app/asset/images/delete_noun_cc.svg
   create src/app/asset/images/edit_noun_cc.svg
   create src/app/asset/images/failed_noun_cc.svg
   create src/app/asset/images/success_noun_cc.svg
   create src/app/data.service.ts
   create src/app/home/home.component.css
   create src/app/home/home.component.html
   create src/app/home/home.component.ts
   create src/environments/environment.prod.ts
   create src/environments/environment.ts
   create src/favicon.ico
   create src/index.html
   create src/main.ts
   create src/polyfills.ts
   create src/styles.css
   create src/test.ts
   create src/tsconfig.app.json
   create src/tsconfig.json
   create src/tsconfig.spec.json
   create tsconfig.json
   create tslint.json
   create .angular-cli.json
   create .editorconfig
   create .gitignore
   create .dockerignore
   create .cfignore
   create .npmignore
   create src/app/SampleAsset/SampleAsset.component.ts
   create src/app/SampleAsset/SampleAsset.service.ts
   create src/app/SampleAsset/SampleAsset.component.spec.ts
   create src/app/SampleAsset/SampleAsset.component.html
   create src/app/SampleAsset/SampleAsset.component.css
   create src/app/SampleParticipant/SampleParticipant.component.ts
   create src/app/SampleParticipant/SampleParticipant.service.ts
   create src/app/SampleParticipant/SampleParticipant.component.spec.ts
   create src/app/SampleParticipant/SampleParticipant.component.html
   create src/app/SampleParticipant/SampleParticipant.component.css
   create src/app/SampleTransaction/SampleTransaction.component.ts
   create src/app/SampleTransaction/SampleTransaction.service.ts
   create src/app/SampleTransaction/SampleTransaction.component.spec.ts
   create src/app/SampleTransaction/SampleTransaction.component.html
   create src/app/SampleTransaction/SampleTransaction.component.css


I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.


npm install过程略

added 1178 packages from 1402 contributors and audited 9765 packages in 68.771s
found 35 vulnerabilities (15 low, 8 moderate, 12 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Application generated

cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain/CSupplyChain$ nf serve
nf: command not found
cielo@cielo-ThinkPad-E550:~/cprogrames/csupplychain/CSupplyChain$ ng serve
Your global Angular CLI version (7.3.8) is greater than your local
version (1.0.1). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
** NG Live Development Server is running on http://localhost:4200 **
Hash: 4f13260bee9704e3d77b                                                               
Time: 24020ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 297 kB {5} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 101 kB {4} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 184 kB {5} [initial] [rendered]
chunk    {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 464 kB {5} [initial] [rendered]
chunk    {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.16 MB [initial] [rendered]
chunk    {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.

<think>嗯,用户问的是关于Maven中一个特定的依赖项迁移问题:xml-apis:xml-apis:jar:2.0.2被重定位到1.0.b2版本。首先,我需要确定用户为什么会遇到这个问题。通常这种情况发生在使用Maven构建项目时,可能出现了依赖冲突或者版本不兼容的警告。用户可能是在构建日志中看到相关的提示信息,所以想知道如何处理。 接下来,我需要回忆xml-apis这个库的相关信息。xml-apis原本是Apache Xerces项目的一部分,提供了XML相关的API,比如DOM、SAX等。但后来,这个库被拆分或重新组织,导致不同版本之间的变动。尤其是2.0.2版本可能已经被标记为过时,或者被重定向到另一个版本,比如1.0.b2,这可能是因为项目维护者进行了版本号的调整或者模块的重组。 用户的问题中提到“relocated”,这在Maven中通常指的是使用<relocation>标签进行的依赖重定向。当一个artifact被移动到不同的groupId或artifactId时,Maven仓库会通过重定向来确保向后兼容,但版本号的变化可能意味着存在重大变更或修复。需要解释为什么会出现这种情况,可能的原因包括版本错误、依赖冲突,或者维护者主动调整。 然后,我需要考虑用户的实际需求。用户可能希望解决构建中的警告或错误,或者想知道是否需要手动修改pom.xml中的依赖声明。需要给出具体的解决步骤,比如如何排除旧版本,引入新版本,或者确认是否需要升级到其他替代库,比如使用XML相关的标准API或引入新的依赖如xercesImpl。 另外,用户可能需要了解更深层次的原因,比如为什么版本号反而从2.0.2降到了1.0.b2,这可能是版本管理上的混乱,或者是维护者重新组织了项目结构,导致版本号的重新设定。需要解释清楚这种情况在开源项目中可能发生的原因,以及如何正确应对。 还需要检查是否有常见的误操作或误解,比如用户可能误以为版本号越高越好,但在这里反而需要降级,所以需要解释版本号变化背后的原因,避免用户产生困惑。同时,提醒用户注意依赖冲突,使用Maven的依赖树分析工具来排查问题,确保项目稳定。 最后,总结解决步骤,提供示例代码,让用户能够直接修改pom.xml,并验证是否解决了问题。同时,给出进一步的建议,比如寻找替代库或升级到更新的版本,保持项目的依赖健康。</think>关于 `xml-apis:xml-apis:jar` 的版本重定向问题,以下是技术解析和解决方案: --- ### 1. **现象解释** 当 Maven 提示 `xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2`,表示该依赖的**元数据已被官方重新映射**。 本质是:**旧版本 `2.0.2` 被标记为废弃**,并强制指向 `1.0.b2` 版本。 --- ### 2. **根本原因** - **历史背景**:`xml-apis` 是 Apache Xerces 项目的衍生库,早期用于提供 XML 解析相关 API(如 DOM、SAX 等)。 - **版本混乱**:由于历史维护问题,`2.0.2` 版本实际是**错误发布**的版本号,官方最终将其修正为 `1.0.b2`。 - **Maven 重定向**:通过 `pom.xml` 中的 `<relocation>` 标签强制修正版本映射。 --- ### 3. **影响范围** | 问题类型 | 具体表现 | |----------------|-------------------------------| | **依赖冲突** | 多个模块同时声明不同版本 | | **构建警告** | `mvn install` 输出版本重定向提示 | | **运行时错误** | 类加载冲突(如 `NoSuchMethodError`)| --- ### 4. **解决方案** #### 步骤 1:显式声明正确版本 在 `pom.xml` 中**强制指定版本**,覆盖旧版本: ```xml <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> <version>1.0.b2</version> </dependency> ``` #### 步骤 2:排除冲突依赖 若其他库间接引用了 `2.0.2`,需手动排除: ```xml <dependency> <groupId>some.library</groupId> <artifactId>problematic-lib</artifactId> <exclusions> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> </dependency> ``` #### 步骤 3:验证依赖树 通过命令检查最终依赖版本: ```bash mvn dependency:tree -Dincludes=xml-apis:xml-apis ``` --- ### 5. **替代方案建议** - **优先使用标准 API**:Java 6+ 已内置 `javax.xml` 包,无需额外依赖 `xml-apis`。 - **升级到新库**:改用 `xerces:xercesImpl` 提供完整 XML 解析支持: ```xml <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.2</version> </dependency> ``` --- ### 6. **技术总结** | 关键点 | 说明 | |-----------------------|--------------------------------------------------------------------| | **版本重定向本质** | Maven 仓库元数据修正,非代码变更 | | **长期建议** | 避免直接依赖 `xml-apis`,改用 Java 原生 API 或 `xercesImpl` | | **兼容性检查** | 确保 `1.0.b2` 与其他库(如 Xalan、Saxon)无冲突 | 通过以上操作可解决版本冲突问题。若仍遇异常,需检查是否有多处隐式依赖未排除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值