我无法使用SAM构建我的Spring Boot多模块项目。

huangapple go评论53阅读模式
英文:

I cant build my spring-boot multi module project with SAM

问题

在运行SAM构建时,我在依赖于项目内另一个本地模块的模块上遇到了依赖错误。从mvn或IntelliJ中没有问题,但当我执行SAM构建时,我遇到了找不到符号和类的错误。

构建失败
错误:JavaMavenWorkflow:MavenBuild - Maven失败:[INFO]扫描项目...
[INFO]-------------------------------------------------- ----------------------
[INFO]反应堆构建顺序:
[INFO]
[INFO]后端[pom]
[INFO] Api [jar]
[INFO]注册[jar]
[INFO]
[INFO]------------------------<com.backend:backend>-------------------------
[INFO]正在构建后端0.0.1-SNAPSHOT[1/3]
[INFO]--------------------------------[pom]---------------------------------
[INFO]
[INFO] ---maven-clean-plugin:3.2.0:clean(default-clean)@backend---
[INFO]
[INFO] ---spring-boot-maven-plugin:3.0.6:repackage(重新打包)@backend---
[INFO]
[INFO] ---maven-install-plugin:3.0.1:install(default-install)@backend---
[INFO]正在安装/tmp/tmptflbmqgd/pom.xml到/home/laingard/.m2/repository/com/backend/backend/0.0.1-SNAPSHOT/backend-0.0.1-SNAPSHOT.pom
[INFO]
[INFO]--------------------------<com.backend:Api>---------------------------
[INFO]构建Api 0.0.1-SNAPSHOT[2/3]
[INFO]--------------------------------[jar]---------------------------------
[INFO]
[INFO] ---maven-clean-plugin:3.2.0:clean(default-clean)@Api---
[INFO]删除/tmp/tmptflbmqgd/Api/target
[INFO]
[INFO] ---maven-resources-plugin:3.3.1:resources(默认资源)@Api---
[INFO]从src/main/resources复制0个资源到target/classes
[INFO]跳过不存在的resourceDirectory /tmp/tmptflbmqgd/Api/config
[INFO]
[INFO] ---maven-compiler-plugin:3.10.1:compile(默认编译)@Api---
[INFO]检测到更改-重新编译模块!
[INFO]正在编译93个源文件到/tmp/tmptflbmqgd/Api/target/classes
[INFO]
[INFO] ---maven-resources-plugin:3.3.1:testResources(默认测试资源)@Api---
[INFO]跳过不存在的resourceDirectory /tmp/tmptflbmqgd/Api/src/test/resources
[INFO]
[INFO] ---maven-compiler-plugin:3.10.1:testCompile(默认测试编译)@Api---
[INFO]检测到更改-重新编译模块!
[INFO]
[INFO] ---maven-surefire-plugin:2.22.2:test(默认测试)@Api---
[INFO]跳过测试。
[INFO]
[INFO] ---maven-jar-plugin:3.3.0:jar(默认jar)@Api---
[INFO]正在构建jar:/tmp/tmptflbmqgd/Api/target/Api-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] ---spring-boot-maven-plugin:3.0.6:repackage(重新打包)@Api---
[INFO]用重新打包的存档替换主要存档
[INFO]
[INFO] ---maven-install-plugin:3.0.1:install(default-install)@Api---
[INFO]正在安装/tmp/tmptflbmqgd/Api/pom.xml到/home/laingard/.m2/repository/com/backend/Api/0.0.1-SNAPSHOT/Api-0.0.1-SNAPSHOT.pom
[INFO]正在将/tmp/tmptflbmqgd/Api/target/Api-0.0.1-SNAPSHOT.jar安装到/home/laingard/.m2/repository/com/backend/Api/0.0.1-SNAPSHOT/Api-0.0.1-SNAPSHOT.jar
[INFO]
[INFO]------------------------<com.backend:Register>------------------------
[INFO]构建注册0.0.1-SNAPSHOT[3/3]
[INFO]--------------------------------[jar]---------------------------------
[INFO]
[INFO] ---maven-clean-plugin:3.2.0:clean(default-clean)@Register---
[INFO]删除/tmp/tmptflbmqgd/Register/target
[INFO]
[INFO] ---maven-resources-plugin:3.3.1:resources(默认资源)@Register---
[INFO]从src/main/resources复制0个资源到target/classes
[INFO]跳过不存在的resourceDirectory /tmp/tmptflbmqgd/Register/config
[INFO]
[INFO] ---maven-compiler-plugin:3.10.1:compile(默认编译)@Register---
[INFO]检测到更改-重新编译模块!
[INFO]正在编译9个源文件到/tmp/tmptflbmqgd/Register/target/classes
[INFO]-------------------------------------------------------------
[ERROR] COMPILATION ERROR:
[INFO]-------------------------------------------------------------
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[3,34]包com.careerwatch.Api.entity不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[4,37]包com.careerwatch.Api.exception不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[5,38]包com.careerwatch.Api.repository不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[18,19]找不到符号
符号:类UserRepository
位置:类com.careerwatch.register.service.RegisterServiceImpl
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[3,34]包com.careerwatch.Api.entity不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[4,38]包com.careerwatch.Api.repository不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/mapper/RegisterDtoMapper.java:[3,34]包com.careerwatch.Api.entity不存在
[ERROR]/tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[15,1]找不到符号
符号:类User

<details>
<summary>英文:</summary>

When running SAM build, I get a dependency error on the module that depends on another local module within my project. From mvn or IntelliJ I have no problems, but when i execute SAM build, i got an error of notFound symbols and classses.

Build Failed
Error: JavaMavenWorkflow:MavenBuild - Maven Failed: [INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] backend                                                            [pom]
[INFO] Api                                                                [jar]
[INFO] Register                                                           [jar]
[INFO]
[INFO] ------------------------&lt; com.backend:backend &gt;-------------------------
[INFO] Building backend 0.0.1-SNAPSHOT                                    [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ backend ---
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.6:repackage (repackage) @ backend ---
[INFO]
[INFO] --- maven-install-plugin:3.0.1:install (default-install) @ backend ---
[INFO] Installing /tmp/tmptflbmqgd/pom.xml to /home/laingard/.m2/repository/com/backend/backend/0.0.1-SNAPSHOT/backend-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --------------------------&lt; com.backend:Api &gt;---------------------------
[INFO] Building Api 0.0.1-SNAPSHOT                                        [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ Api ---
[INFO] Deleting /tmp/tmptflbmqgd/Api/target
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ Api ---
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] skip non existing resourceDirectory /tmp/tmptflbmqgd/Api/config
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ Api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 93 source files to /tmp/tmptflbmqgd/Api/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:testResources (default-testResources) @ Api ---
[INFO] skip non existing resourceDirectory /tmp/tmptflbmqgd/Api/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ Api ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ Api ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ Api ---
[INFO] Building jar: /tmp/tmptflbmqgd/Api/target/Api-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.6:repackage (repackage) @ Api ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:3.0.1:install (default-install) @ Api ---
[INFO] Installing /tmp/tmptflbmqgd/Api/pom.xml to /home/laingard/.m2/repository/com/backend/Api/0.0.1-SNAPSHOT/Api-0.0.1-SNAPSHOT.pom
[INFO] Installing /tmp/tmptflbmqgd/Api/target/Api-0.0.1-SNAPSHOT.jar to /home/laingard/.m2/repository/com/backend/Api/0.0.1-SNAPSHOT/Api-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] ------------------------&lt; com.backend:Register &gt;------------------------
[INFO] Building Register 0.0.1-SNAPSHOT                                   [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ Register ---
[INFO] Deleting /tmp/tmptflbmqgd/Register/target
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ Register ---
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] skip non existing resourceDirectory /tmp/tmptflbmqgd/Register/config
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ Register ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to /tmp/tmptflbmqgd/Register/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[4,37] package com.careerwatch.Api.exception does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[5,38] package com.careerwatch.Api.repository does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[18,19] cannot find symbol
symbol:   class UserRepository
location: class com.careerwatch.register.service.RegisterServiceImpl
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[4,38] package com.careerwatch.Api.repository does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/mapper/RegisterDtoMapper.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[15,1] cannot find symbol
symbol:   class UserRepository
location: class com.careerwatch.register.service.RegisterServiceImpl
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/mapper/RegisterDtoMapper.java:[13,12] cannot find symbol
symbol:   class User
location: class com.careerwatch.register.mapper.RegisterDtoMapper
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[26,5] cannot find symbol
symbol:   class UserRepository
location: class com.careerwatch.register.jwt.JwtService
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[34,33] cannot find symbol
symbol:   class User
location: class com.careerwatch.register.jwt.JwtService
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[66,47] cannot find symbol
symbol:   class User
location: class com.careerwatch.register.jwt.JwtService
[INFO] 12 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for backend 0.0.1-SNAPSHOT:
[INFO]
[INFO] backend ............................................ SUCCESS [  0.565 s]
[INFO] Api ................................................ SUCCESS [  3.314 s]
[INFO] Register ........................................... FAILURE [  0.534 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.575 s
[INFO] Finished at: 2023-06-01T12:51:53-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project Register: Compilation failure: Compilation failure:
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[4,37] package com.careerwatch.Api.exception does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[5,38] package com.careerwatch.Api.repository does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[18,19] cannot find symbol
[ERROR]   symbol:   class UserRepository
[ERROR]   location: class com.careerwatch.register.service.RegisterServiceImpl
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[4,38] package com.careerwatch.Api.repository does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/mapper/RegisterDtoMapper.java:[3,34] package com.careerwatch.Api.entity does not exist
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/service/RegisterServiceImpl.java:[15,1] cannot find symbol
[ERROR]   symbol:   class UserRepository
[ERROR]   location: class com.careerwatch.register.service.RegisterServiceImpl
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/mapper/RegisterDtoMapper.java:[13,12] cannot find symbol
[ERROR]   symbol:   class User
[ERROR]   location: class com.careerwatch.register.mapper.RegisterDtoMapper
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[26,5] cannot find symbol
[ERROR]   symbol:   class UserRepository
[ERROR]   location: class com.careerwatch.register.jwt.JwtService
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[34,33] cannot find symbol
[ERROR]   symbol:   class User
[ERROR]   location: class com.careerwatch.register.jwt.JwtService
[ERROR] /tmp/tmptflbmqgd/Register/src/main/java/com/careerwatch/register/jwt/JwtService.java:[66,47] cannot find symbol
[ERROR]   symbol:   class User
[ERROR]   location: class com.careerwatch.register.jwt.JwtService
[ERROR] -&gt; [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 &lt;args&gt; -rf :Register

This is my template.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Globals:
Function:
Timeout: 30

Resources:
CareerWatchFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: com.careerwatch.Api.StreamLambdaHandler::handleRequest
Runtime: java17
AutoPublishAlias: production
SnapStart:
ApplyOn: PublishedVersions
Architectures:
- x86_64
MemorySize: 1024
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: CareerWatchApi
DB_HOST: !Ref DBhost
DB_PORT: !Ref DBport
DB_NAME: !Ref DBname
DB_USERNAME: !Ref DBusername
DB_PASSWORD: !Ref DBpassword
Events:
HelloWorld:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
RegisterFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: com.careerwatch.register.RegisterLambdaHandler::handleRequest
Runtime: java17
AutoPublishAlias: production
SnapStart:
ApplyOn: PublishedVersions
Architectures:
- x86_64
MemorySize: 1024
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: CareerWatchApi
DB_HOST: !Ref DBhost
DB_PORT: !Ref DBport
DB_NAME: !Ref DBname
DB_USERNAME: !Ref DBusername
DB_PASSWORD: !Ref DBpassword
SECRET_KEY: !Ref SecretKey
Events:
RegisterEndpoint:
Type: Api
Properties:
Path: /api/v1/register
Method: POST
Parameters:
DBhost:
Type: String
Default: ''
Description: Enter the DB host name or IP address
DBport:
Type: String
Default: ''
Description: Enter the DB port
DBname:
Type: String
Default: ''
Description: Enter the DB name
DBusername:
Type: String
Default: ''
Description: Enter the DB username
DBpassword:
Type: String
Default: ''
Description: Enter the DB password
SecretKey:
Type: String
Default: ''
Description: Enter the secret jwt key password


I did `mvn install` and I checked the whole project structure, however with maven it works, but with sam build it doesn&#39;t.
[1]: https://i.stack.imgur.com/fy3Cw.jpg
</details>
# 答案1
**得分**: 0
你在评论中提到:
"我正在构建一个无服务器应用程序,部署Lambda函数在API Gateway中。"
如果你有兴趣使用Java构建无服务器应用程序,请查看PAM示例。此示例构建了一个完整的无服务器示例,使用API Gateway、Lambda函数、Java SDK、一个使用Cognito登录用户的客户端应用程序等等。
以下是概述图示:
[![在此输入图片描述][1]][1]
此外,该示例使用AWS CDK来创建各种资源。
这不使用SAM。
请参阅:
[创建一个照片资产管理应用程序,让用户使用标签管理照片][2]
[1]: https://i.stack.imgur.com/iBcyY.png
[2]: https://docs.aws.amazon.com/code-library/latest/ug/cross_PAM_java_2_topic.html
<details>
<summary>英文:</summary>
You stated in your comment: 
&quot;I am building a serverless application, deploying lambdas functions in api gateway.&quot;
If you are intereted in builidng a serverless app with Java, look at the PAM example. This example builds a complete serverless example that uses API Gateway, Lambda functions, Java SDK, a client app that uses Cognito to log in users, etc. 
Here is the overview illustration:
[![enter image description here][1]][1]
As well, this example uses the AWS CDK to standup various resources. 
This does not use SAM. 
See:
[Create a photo asset management application that lets users manage photos using labels][2]
[1]: https://i.stack.imgur.com/iBcyY.png
[2]: https://docs.aws.amazon.com/code-library/latest/ug/cross_PAM_java_2_topic.html
</details>

huangapple
  • 本文由 发表于 2023年6月2日 00:08:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定