升级到 java 17 和 spring 3.1.0 后,SQS 侦听器无法工作。它在 java 11 和 spring 2.5.2 上运行良好
我们遇到的第一个错误是:未找到 AmazonSQS bean。 错误:com.pchf.notification.accessors.SQSAccessor 中的字段 amazonSQS 需要类型为“com.amazonaws.services.sqs.AmazonSQS”的 bean,但无法找到。
解决方案:我们通过配置手动为 Amazon SQS 创建 Bean(之前 java 11 不需要)
结论:运行服务时没有错误
服务启动日志供参考:
12:07:13.964 [background-preinit] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 8.0.0.Final trace_id= span_id=
12:07:14.052 [main] INFO c.p.notification.NotificationService - Starting NotificationService using Java 17.0.7 with PID 71845 (/Users/abhishekchahar/IdeaProjects/latest/new10/notification-service/target/classes started by abhishekchahar in /Users/abhishekchahar/IdeaProjects/latest/new10/notification-service) trace_id= span_id=
12:07:14.055 [main] INFO c.p.notification.NotificationService - No active profile set, falling back to 1 default profile: "default" trace_id= span_id=
12:07:16.854 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode trace_id= span_id=
12:07:16.857 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data MongoDB repositories in DEFAULT mode. trace_id= span_id=
12:07:17.063 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 200 ms. Found 2 MongoDB repository interfaces. trace_id= span_id=
12:07:17.104 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode trace_id= span_id=
12:07:17.106 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data Redis repositories in DEFAULT mode. trace_id= span_id=
12:07:17.129 [main] INFO o.s.d.r.c.RepositoryConfigurationExtensionSupport - Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.pchf.notification.repository.DLTTemplateRepository; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository trace_id= span_id=
12:07:17.129 [main] INFO o.s.d.r.c.RepositoryConfigurationExtensionSupport - Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.pchf.notification.repository.SMSCommunicationRepo; If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository trace_id= span_id=
12:07:17.130 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 18 ms. Found 0 Redis repository interfaces. trace_id= span_id=
12:07:17.660 [main] INFO o.s.cloud.context.scope.GenericScope - BeanFactory id=4ca4e4fd-d534-34a2-b950-b3840b82ecee trace_id= span_id=
12:07:17.764 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'com.pchf.notification.clients.DocumentGenerationServiceClient' of type [org.springframework.cloud.openfeign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) trace_id= span_id=
12:07:17.767 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'com.pchf.client.fcs.client.FcsClient' of type [org.springframework.cloud.openfeign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) trace_id= span_id=
12:07:18.929 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8002 (http) trace_id= span_id=
12:07:18.943 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8002"] trace_id= span_id=
12:07:18.944 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] trace_id= span_id=
12:07:18.945 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.8] trace_id= span_id=
12:07:19.107 [main] INFO o.a.c.c.C.[.[.[/api/v1/notification] - Initializing Spring embedded WebApplicationContext trace_id= span_id=
12:07:19.112 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 4954 ms trace_id= span_id=
12:07:21.425 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|spring-boot", "version": "4.9.1"}, "os": {"type": "Darwin", "name": "Mac OS X", "architecture": "x86_64", "version": "13.3.1"}, "platform": "Java/Amazon.com Inc./17.0.7+7-LTS"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=majority, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=null, userName='prf_intengg_mongo_dev_common_user', source='admin', password=<hidden>, mechanismProperties=<hidden>}, streamFactoryFactory=null, commandListeners=[io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener@67167f8f], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@1e5190bd, com.mongodb.Jep395RecordCodecProvider@733345f5]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[127.0.0.1:27017], srvHost=piramal-mongo-dev-cluster-pl-0.fh5op.mongodb.net, srvServiceName=mongodb, mode=MULTIPLE, requiredClusterType=REPLICA_SET, requiredReplicaSetName='atlas-x30zfr-shard-0', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolListener@5add7380], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=true, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, contextProvider=null} trace_id= span_id=
12:07:21.868 [main] INFO org.mongodb.driver.cluster - Cluster description not yet available. Waiting for 30000 ms before timing out trace_id= span_id=
12:07:22.500 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-srv-piramal-mongo-dev-cluster-pl-0.fh5op.mongodb.net] INFO org.mongodb.driver.cluster - Adding discovered server pl-0-ap-south-1.fh5op.mongodb.net:1027 to client view of cluster trace_id= span_id=
12:07:22.527 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-srv-piramal-mongo-dev-cluster-pl-0.fh5op.mongodb.net] INFO org.mongodb.driver.cluster - Adding discovered server pl-0-ap-south-1.fh5op.mongodb.net:1029 to client view of cluster trace_id= span_id=
12:07:22.532 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-srv-piramal-mongo-dev-cluster-pl-0.fh5op.mongodb.net] INFO org.mongodb.driver.cluster - Adding discovered server pl-0-ap-south-1.fh5op.mongodb.net:1028 to client view of cluster trace_id= span_id=
12:07:22.537 [main] INFO org.mongodb.driver.cluster - No server chosen by com.mongodb.client.internal.MongoClientDelegate$$Lambda$1250/0x00000008017d5378@434a2a10 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1027, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1029, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1028, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out trace_id= span_id=
12:07:23.465 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-pl-0-ap-south-1.fh5op.mongodb.net:1027] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1027, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=800810041, setName='atlas-x30zfr-shard-0', canonicalAddress=pl-0-ap-south-1.fh5op.mongodb.net:1027, hosts=[pl-0-ap-south-1.fh5op.mongodb.net:1027, pl-0-ap-south-1.fh5op.mongodb.net:1028, pl-0-ap-south-1.fh5op.mongodb.net:1029], passives=[], arbiters=[], primary='pl-0-ap-south-1.fh5op.mongodb.net:1029', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='AP_SOUTH_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=4, topologyVersion=TopologyVersion{processId=6470caa678e15e46058920a2, counter=4}, lastWriteDate=Wed May 31 12:07:21 IST 2023, lastUpdateTimeNanos=304578047529375} trace_id= span_id=
12:07:23.465 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-pl-0-ap-south-1.fh5op.mongodb.net:1028] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1028, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=805697542, setName='atlas-x30zfr-shard-0', canonicalAddress=pl-0-ap-south-1.fh5op.mongodb.net:1028, hosts=[pl-0-ap-south-1.fh5op.mongodb.net:1027, pl-0-ap-south-1.fh5op.mongodb.net:1028, pl-0-ap-south-1.fh5op.mongodb.net:1029], passives=[], arbiters=[], primary='pl-0-ap-south-1.fh5op.mongodb.net:1029', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='AP_SOUTH_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=4, topologyVersion=TopologyVersion{processId=6470cbfbffbbb55d0f0378be, counter=3}, lastWriteDate=Wed May 31 12:07:21 IST 2023, lastUpdateTimeNanos=304578049978375} trace_id= span_id=
12:07:23.465 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-pl-0-ap-south-1.fh5op.mongodb.net:1029] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=pl-0-ap-south-1.fh5op.mongodb.net:1029, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=803997750, setName='atlas-x30zfr-shard-0', canonicalAddress=pl-0-ap-south-1.fh5op.mongodb.net:1029, hosts=[pl-0-ap-south-1.fh5op.mongodb.net:1027, pl-0-ap-south-1.fh5op.mongodb.net:1028, pl-0-ap-south-1.fh5op.mongodb.net:1029], passives=[], arbiters=[], primary='pl-0-ap-south-1.fh5op.mongodb.net:1029', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='AWS'}, Tag{name='region', value='AP_SOUTH_1'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=7fffffff00000000000000b5, setVersion=4, topologyVersion=TopologyVersion{processId=6470cb4278cd03cfafce95f8, counter=6}, lastWriteDate=Wed May 31 12:07:21 IST 2023, lastUpdateTimeNanos=304578050238209} trace_id= span_id=
12:07:23.491 [cluster-ClusterId{value='6476eb21570f6b2348e7b308', description='null'}-pl-0-ap-south-1.fh5op.mongodb.net:1029] INFO org.mongodb.driver.cluster - Discovered replica set primary pl-0-ap-south-1.fh5op.mongodb.net:1029 with max election id 7fffffff00000000000000b5 and max set version 4 trace_id= span_id=
12:07:25.132 [main] INFO c.p.n.e.h.DefaultExceptionHandler - DefaultExceptionHandler created trace_id= span_id=
12:07:25.194 [main] INFO c.p.n.e.h.PinpointExceptionHandler - PinpointExceptionHandler created trace_id= span_id=
12:07:25.198 [main] INFO c.p.n.e.h.ServiceExceptionHandler - ServiceExceptionHandler created trace_id= span_id=
12:07:26.458 [main] INFO c.p.n.configs.JedisPoolConfiguration - redisHostName - redis-master-dev.pchf.in, redisPort - 6379 trace_id= span_id=
12:07:27.236 [main] WARN i.a.c.a.c.CredentialsProviderAutoConfiguration - Skipping creating `StsCredentialsProvider`. `software.amazon.awssdk:sts` is on the classpath, but neither `spring.cloud.aws.credentials.sts` properties are configured nor `AWS_WEB_IDENTITY_TOKEN_FILE` or the javaproperty `aws.webIdentityTokenFile` is set trace_id= span_id=
12:07:28.362 [main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing 5 endpoint(s) beneath base path '/actuator' trace_id= span_id=
12:07:28.455 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8002"] trace_id= span_id=
12:07:28.467 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8002 (http) with context path '/api/v1/notification' trace_id= span_id=
12:07:28.497 [main] INFO c.p.notification.NotificationService - Started NotificationService in 15.393 seconds (process running for 16.25) trace_id= span_id=
12:07:28.509 [main] INFO c.p.notification.NotificationService - Notification Service Started!! trace_id= span_id=
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-sqs</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>software.amazon.msk</groupId>
<artifactId>aws-msk-iam-auth</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.74</version>
<type>pom</type>
<scope>import</scope>
</dependency>
请提供任何建议或调试步骤帮助。
Spring Cloud AWS
2.x.
与 Spring Boot 3.x
不兼容。您还必须将 AWS 依赖项迁移到 3.x
才能使其正常工作。以下是信息:https://github.com/awspring/spring-cloud-aws/releases/tag/v3.0.0
我们遇到了同样的问题。 我们在 application.yml 上有一个属性 当启用延迟初始化时。 SqsListener 未启动。 该财产已被解决为已删除。
spring:
main:
lazy-initialization: true