小编use*_*604的帖子

如何在@SpringBootApplication测试中排除带有@Configuration的类

我正在使用一个名为 spring-cloud-aws 的依赖模块。它有一个 @Configuration 类,如 org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration 在我的 SpringBoot JUnit 测试用例中,SqsConfiguration 类正在被检测到,并且 Bean 正在被初始化。我想在 JUNit 测试用例的类中排除此配置。如何实现这一目标?

我尝试使用@ComponentScan,但没有成功。

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SQLTestConfig.class)
@ActiveProfiles("test")
public class BusinessManagerTest {

}

@TestConfiguration
@ComponentScan(basePackages = {"package1","package1"},
excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SqsConfiguration.class)})
@Profile("test")
class SQLTestConfig {   

    @Bean
    public SomeBean beans() {

        return new SomeBean();
    }



}
Run Code Online (Sandbox Code Playgroud)

加载此配置类需要可用的 aws 凭证。我不想注入凭据来运行简单的 Bean 测试用例。

org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.class]中定义的名为“simpleMessageListenerContainer”的bean时出错:调用init方法失败;嵌套异常是 com.amazonaws.services.sqs.model.AmazonSQSException:请求中包含的安全令牌已过期

spring-boot spring-cloud-aws

5
推荐指数
1
解决办法
6319
查看次数

Cloudformation 依赖问题 - AWS::Serverless::Function 中的 AutoPublishAlias

我正在使用 SAM 模板来部署 Lambda 函数和 api 网关。我正在使用 AWS::Serverless::Function 来定义我的 lambda 函数。我正在使用 AWS::Serverless::Api 来定义我的 API。我还使用 AWS::Lambda::Permission 授予该函数的 apigateway 权限。

问题是 AWS::Lambda::Permission 的资源创建失败,因为我的别名不可用。我的 LambdaFunction 资源创建了别名,但在它被创建之前,Lambda 权限资源创建被触发,如果没有看到提到的别名,它就会失败。

我使用“aws cloudformation deploy”来部署模板

将 DependsOn 属性添加到 LambdaPermission 资源不起作用

> LambdaFunction:
>     Type: AWS::Serverless::Function
>     Properties:
>       Handler: MyHandler
>       Runtime: !Ref LambdaJavaVersion
>       CodeUri: ./build.jar
>       Description: !Sub "${LambdaName} function"
>       Role: !GetAtt LambdaIAMRole.Arn
>       FunctionName: !Ref LambdaName
>       AutoPublishAlias: prod
> APIResource:
>   DependsOn: LambdaFunction
>   Type: AWS::Serverless::Api
>   Properties:
>     DefinitionUri: ./swagger/swagger.yml
>     EndpointConfiguration: …
Run Code Online (Sandbox Code Playgroud)

aws-sam

1
推荐指数
1
解决办法
659
查看次数

标签 统计

aws-sam ×1

spring-boot ×1

spring-cloud-aws ×1